Multiplying a list object with a negative integer.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zendas
    New Member
    • Apr 2010
    • 2

    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.
    Code:
    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?
    Last edited by bvdet; Apr 7 '10, 06:03 AM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    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.

    Comment

    • zendas
      New Member
      • Apr 2010
      • 2

      #3
      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.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        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:
        Code:
        >>> 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

        Comment

        Working...