0
# This program calculates rate and distance problems print "Input a rate and a distance" rate = input("Rate: ") distance = input("Distance: ") print "Time:", (distance / rate)
i have problem with this code
4 Réponses
+ 2
here
rate = float (input ())
and same for distance Too you can use any data type like int or any other.
in your case the input accepted is a string value and
thus will show you an error
0
you have to use parentheses around print if you are using newer version of Python.
0
First u r mention parentheses, then mention what datatype.
0
input gives you str.
str has no method for /
It will not work if you don't adapt your values.
Also print is a function in Python 3.x and not a statement as in Python 2.x. Use parentheses.
Last but not least, you should use a function for the calculation, like:
def time(rate, distance):
return distance / rate
cleaner, more modern, and reusable infinitely many times