Write a program to display the distance in meters and feet for the values entered in kilometer. [1 km=1000m, 1feet=30cm]
Answers
I'm giving you the idea
print("Enter the distance between two cities(in km) : ")
km = float(input())
m = km * 1000 # 1km = 1000m
feet = km * 3280.84 # 1km=3280.84feet
inch = km * 39370.1 #1 km=39370.1inches
cm = km * 100000 #1km = 100000cm
print("\nDistance in Kilometres = ", km)
print("\nDistance in Metres = ", m)
print("\nDistance in Feet = ", feet)
print("\nDistance in Centimetres = ", cm)
Answer:
# Get the distance in kilometers from the user
distance_in_km = float(input("Enter the distance in kilometers: "))
# Convert kilometers to meters and feet
distance_in_meters = distance_in_km * 1000
distance_in_feet = distance_in_km * 1000 * 3.281
# Display the results
print("Distance in meters:", distance_in_meters, "m")
print("Distance in feet:", distance_in_feet, "ft")
In this program, we first get the user's distance in kilometers via the input function. We convert the distance to meters by multiplying it by 1000 because 1 kilometer equals 1000 meters. We also convert the distance to feet by multiplying it by 1000 (to convert kilometers to meters) and then by 3.281 (since 1 foot equals 0.3048 meters).
Finally, we show the results with the print function. We include units (meters and feet) in the output to make it clear what the values represent.
Here is an example of what the output of the program might look like:
Enter the distance in kilometers: 2.5
Distance in meters: 2500.0 m
Distance in feet: 8202.1 ft
View more Python Programs :
https://brainly.in/question/18675738
#SPJ2