Here is my code but getting a error
Learning Python Code needed ask user number miles driven, gallons of gas used caluculate car mpg display result?

miles_driven=raw_input("How many miles have you driven?\n")
gallons_of_gas_used=raw_input("Now how much gas have you used?\n")

print int(miles_driven) / int(gallons_of_gas_used)

8 Years
Discussion Span
Last Post by vegaseat

Check what python version you have, i think you may have python 3.1 which means that you would not have such thing as a raw_input statement.

So instead of raw_input , just replace it with input . That should sort things out.

Also remember for posting in the future, it is a lot easier for us to understand your problem if you post your error message

Hope that helps :)


and you should use float instead of int

print float(miles_driven) / float(gallons_of_gas_used)
Votes + Comments
a good deduction

jice is right. Judging from raw_input() and the print statement you are using a Python2 version. There the '/' will do an integer division if you have integers, so 2/5 would give you zero. This has changed with the advent of Python3 where '/' will give you a floating point result and '//' is now the official integer division symbol.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.