Objective
Create a Python program that converts units of length, mass and temperature using factor tables in dictionaries and a conversion function.
Instructions
- Read an integer
nand thennlines with the formatVALUE FROM TO(VALUEis a decimal number). - Length units:
m,km(1000 m),cm(0.01 m),mi(1609.344 m),ft(0.3048 m). Mass:kg,g(0.001 kg),lb(0.45359237 kg). Temperature:C,F,K(K = C + 273.15). - If the conversion is valid, show
VALUE FROM = R.RR TOwith the value as it was typed and the result with two decimals. - If a unit does not exist, show
Error: unknown unit X. If they exist but belong to different quantities, showError: incompatible units.
4
10 km mi
100 C F
2.5 kg lb
3 m kg
10 km = 6.21 mi
100 C = 212.00 F
2.5 kg = 5.51 lb
Error: incompatible units
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise