Results 1 to 3 of 3
I have written a section of code in a program I am constructing as a project in my free time:
Code:
def s():
print 'Hard Disk Sustained Transfer Rate Calculator'
...
- 06-12-2007 #1Just Joined!
- Join Date
- Nov 2006
- Location
- ~/
- Posts
- 40
More python - entering decimals with int(raw_input
I have written a section of code in a program I am constructing as a project in my free time:
In the input for average latency, cylinder switch time, and head switch time, there is often a decimal to input (ex. 1.5). I get an error when I do this, though.Code:def s(): print 'Hard Disk Sustained Transfer Rate Calculator' surfaces = int(raw_input('Enter the number of surfaces : ')) sectorspertrack = int(raw_input('Enter the number of sectors per track : ')) headtime = int(raw_input('Enter the head switch time in ms : ')) cylindertime = int(raw_input('Enter the cylinder switch time in ms : ')) latency = int(raw_input('Enter the average latency in ms : ')) str = ((surfaces * sectorspertrack * 512) / (2 * surfaces * latency + (surfaces - 1) * headtime + cylindertime)) / 1000000 return str
What should I put in for the input so I can enter decimals for the equation?ValueError: invalid literal for int() with base 10: '1.5'
Thanks,
BigFoot
- 06-12-2007 #2
You need to use a float instead of int to enter decimals
Put your hand in an oven for a minute and it will be like an hour, sit beside a beautiful woman for an hour and it will be like a minute, that is relativity. --Albert Einstein
Linux User #425940
Don't PM me with questions, instead post in the forums
- 06-19-2007 #3
Be aware that float can get a bit funny on long calculations. If you're only going a couple decimal places, it probably won't matter, though.
Dan


Reply With Quote