467,119 Members | 1,189 Online

# Multiplying a list object with a negative integer.

 Hi all, I m fairly new to programming so I am sorry if this is a simple answer. I am writing a program that creates a bar graph using a list of numbers. I am having problems multiplying the list object, which are all integers below 16. The reason I am multiplying is to get a clearer visualization of the graph, here is the code. Expand|Select|Wrap|Line Numbers Col1 = [9, 10, 14, 9, 4, 3, 6, 5, 5, 2]   Bwid = 100 b = 0 xpivot = 32 while b < len(Col1):         print "fillrect", xpivot, 380, Bwid / len(Col1), Col1[b] * 2         xpivot = xpivot + 32         b = b + 1 The problem is on the last part of the print statement, 2 is the only number that will work, which is obviously not what I want. I am using a graphing tool that my school has provided called quickdraw. Its frame is 800x600 pixels so it should seemingly fit within the range. Is their something wrong with the code or is it due to the school program? Apr 6 '10 #1
• viewed: 4655
Share:
3 Replies
 Expert Mod 2GB You say that the only number that works is "2", which is not what you want. Can you better explain what you want? I don't understand. I think you are trying to scale your data. Apr 7 '10 #2
 yeah I was trying to scale the data to look better on the program that my school offers. What I ended up doing was changing the list to an integer, like so. int(Col1[b]) * -3 which worked when I was using a positive data scheme. My new problem seems to be when working with negative data input it gives me an error. Should I just change it to float, will that work for negative numbers used as input through the list. Apr 7 '10 #3
 Expert Mod 2GB I am not familiar with quickdraw, but I doubt that quickdraw is the problem. The list elements you were using were already integers. Type casting to float won't help. Take a look at this: Expand|Select|Wrap|Line Numbers >>> Col1 = [9, 10, 14, 9, 4, 3, 6, 5, 5, 2] >>> scale = 2 >>> [i*scale for i in Col1] [18, 20, 28, 18, 8, 6, 12, 10, 10, 4] >>> scale = -2 >>> [i*scale for i in Col1] [-18, -20, -28, -18, -8, -6, -12, -10, -10, -4] >>> limit = 100 >>> scale = limit/max(Col1) >>> scale 7 Apr 7 '10 #4