Python Write Program Asks User Enter Distance Millimeters Prints Amount Distance Kilometer Q37046573

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:

Enter distance in millimeters: 10040050 10 km (s), 40 met(s), 40 cent (s), and 0 mil(s) Process finished with exit code 0

Please up vote the solution if it helped. Thanks!

Output:

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.