Novice · Arithmetic · 33 of 264
Average speed
Read a distance in kilometres and a time in hours, and print the average speed in km/h with one decimal.
Input: distance and time (may have decimals), one per line. Output: <speed> km/h
Examples
Input
100 2
Output
50.0 km/h
Input
42.195 3.5
Output
12.1 km/h
Input
5 0.25
Output
20.0 km/h
One more test checks other inputs when you press Check.
Stuck? The idea behind arithmetic
input() always gives text: turn it into a whole number with int() or a decimal with float() before doing sums.
+ - * / work as in maths; / always gives a decimal. // divides and drops the remainder, % gives the remainder, ** raises to a power.
a = int(input()) b = int(input()) print(a + b) print(a // b, a % b)
Watch for: "5" + "3" is "53", not 8: if a sum joins numbers together, an int() is missing.