Python Forum
trying to get MPG to output as float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to get MPG to output as float
#1
starting = raw_input ("Please enter the starting l/100km:")
ending = raw_input ("Please enter the ending l/100km:")
starting = int (starting)
ending  = int (ending)
#Processing
print (" l per 100km    MPG")
print ("-------------------------------")

for l_per_100km in range (starting,ending+1):
    mpg = 287.5 / l_per_100km
    mpg = float (mpg)
    print "%5i" % l_per_100km, "%12i" % mpg
Reply
#2
on line 12 you should use "%12f"

That said, you should

use python3, not python2
use str.format() method or f-strings (available in python 3.6). check also https://docs.python.org/3/library/string...matstrings
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
hey thanks very much i hafe to use python 2 because of the course im on uses it.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020