-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.py
More file actions
36 lines (27 loc) · 1.04 KB
/
17.py
File metadata and controls
36 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Program No. : 17
#Program : Calculate distance between two cities in km. and change it into meters, feets and inches.
def convert_distance():
print("--- City Distance Converter ---")
# 1. Get distance in kilometers from the user
try:
km = float(input("Enter the distance between two cities (in km): "))
if km < 0:
print("Error: Distance cannot be negative.")
return
except ValueError:
print("Error: Please enter a valid numerical value.")
return
# 2. Perform Conversions
# Kilometers to Meters
meters = km * 1000
# Kilometers to Feet (1 km = 3280.84 feet)
feet = km * 3280.84
# Kilometers to Inches (1 km = 39370.1 inches)
inches = km * 39370.1
# 3. Display the results
print(f"\n--- Conversion Results for {km} km ---")
print(f"Distance in Meters: **{meters:,.2f} m**")
print(f"Distance in Feet: **{feet:,.2f} ft**")
print(f"Distance in Inches: **{inches:,.2f} in**")
# Run the program
convert_distance()