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

21st Sep 2016, 3:25 PM
AYEYEMI ISRAEL
AYEYEMI ISRAEL - avatar
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
22nd Sep 2016, 1:24 PM
Kartik
0
you have to use parentheses around print if you are using newer version of Python.
21st Sep 2016, 3:48 PM
Prashant Goyal
Prashant Goyal - avatar
0
First u r mention parentheses, then mention what datatype.
21st Sep 2016, 7:24 PM
Ramanathan Raveendran
Ramanathan Raveendran - avatar
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
25th Sep 2016, 11:49 AM
Amaras A
Amaras A - avatar