Python
Write a program that asks the user to enter a distance inmillimeters and then prints
the same amount of distance in Kilometers, meters, centimeters, andmillimeters.
For example, 10040050 millimeters is equivalent to. 10 km, 40meters, 5 centimeters, and 0 millimeters(
10 km(s), 40 met(s), 5 cent(s), and 0 mil(s).
Print out the result in the format:
“10 km(s), 40 met(s), 5 cent(s), and 0 mil(s).”
Hint: 1KM – 1000 Meter, 1 Meter = 100 Centimeters, 1Centimeter =10 Millimeters
Solution
d = int(input(“Enter distance in millimeters: “))Kilometers = d//(10**6)d = d % (10**6)meters = d//(10**3)d = d % (10**3)centimeters = d//(10)d = d % (10)print(Kilometers,”km(s),”,meters,”met(s),”,meters,”cent(s), and”,d,”mil(s).”)
Output:
OR
OR