Find the answer to your Linux question:
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' ...
  1. #1
    Just 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:
    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
    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.
    ValueError: invalid literal for int() with base 10: '1.5'
    What should I put in for the input so I can enter decimals for the equation?

    Thanks,
    BigFoot

  2. #2
    Linux Guru Juan Pablo's Avatar
    Join Date
    Mar 2006
    Location
    /home/south_america/ecuador/quito
    Posts
    2,064
    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

  3. #3
    Linux Newbie danbuter's Avatar
    Join Date
    May 2007
    Posts
    108
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...