467,119 Members | 1,189 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,119 developers. It's quick & easy.

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
  1. Col1 = [9, 10, 14, 9, 4, 3, 6, 5, 5, 2]
  2.  
  3. Bwid = 100
  4. b = 0
  5. xpivot = 32
  6. while b < len(Col1):
  7.         print "fillrect", xpivot, 380, Bwid / len(Col1), Col1[b] * 2
  8.         xpivot = xpivot + 32
  9.         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
bvdet
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
bvdet
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
  1. >>> Col1 = [9, 10, 14, 9, 4, 3, 6, 5, 5, 2]
  2. >>> scale = 2
  3. >>> [i*scale for i in Col1]
  4. [18, 20, 28, 18, 8, 6, 12, 10, 10, 4]
  5. >>> scale = -2
  6. >>> [i*scale for i in Col1]
  7. [-18, -20, -28, -18, -8, -6, -12, -10, -10, -4]
  8. >>> limit = 100
  9. >>> scale = limit/max(Col1)
  10. >>> scale
  11. 7
Apr 7 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Danny Winslow | last post: by
1 post views Thread by NickB | last post: by
4 posts views Thread by cplusplus | last post: by
10 posts views Thread by Christoph Zwerschke | last post: by
15 posts views Thread by jaks.maths@gmail.com | last post: by
39 posts views Thread by Frederick Gotham | last post: by
15 posts views Thread by Ivan Novick | last post: by
8 posts views Thread by valentin tihomirov | last post: by
2 posts views Thread by Kirk Strauser | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.