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)

Recommended Answers

All 4 Replies

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 :)

Member Avatar for leegeorg07

yeah, that should work, also can you use the code tags for your code please

and you should use float instead of int

print float(miles_driven) / float(gallons_of_gas_used)
commented: a good deduction +16

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.