473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Multiplying a list object with a negative integer.

2
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
3 6470
bvdet
2,851 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
zendas
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
2,851 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

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

Similar topics

0
by: Danny Winslow | last post by:
I get an unexpected result when I add two negative numbers in PHP on SPARC/Solaris 8. The same program works fine on Intel/Linux. I'm using PHP 4.3.1 on both systems. Here is my program,...
1
by: NickB | last post by:
Please could someone tell me what is wrong. Ther error is: An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll Additional information: Object...
4
by: cplusplus | last post by:
Hello, I have newbie question. I'm stuck on this current assignment. Write a program that prompts the user for two integer values, passes the values to a function where they are multiplied...
4
by: JMCN | last post by:
Hello - This should be an easy function to multiple all amounts if they are negative values (< 0). however, i get an error message on the db.openrecordset because it assumes that i want to count...
10
by: Christoph Zwerschke | last post by:
Currently, if you write 3*'*', you will get '***', but if you write 3.0*'*', you will get an error (can't multiply sequence by non-int). I was wondering whether this should be allowed, i.e....
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
15
by: Ivan Novick | last post by:
Hi, Is it possible to have negative integer literal or only positive? As far as I understand, the code below would be a positive integer literal and the unary negative operator. x = -3.2; ...
8
by: valentin tihomirov | last post by:
My rateonale is: -1 mod 3 = must be 3 0 mod 3 = 0 1 mod 3 = 1 2 mod 3 = 2 3 mod 3 = 3 4 mod 3 = 0 = 1 = 2 = 3
2
by: Kirk Strauser | last post by:
I want to subclass list so that each value in it is calculated at call time. I had initially thought I could do that by defining my own __getitem__, but 1) apparently that's deprecated (although I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.