-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
81 lines (68 loc) · 2.24 KB
/
main.py
File metadata and controls
81 lines (68 loc) · 2.24 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def length_converter():
print("\nLength Conversion Options:")
print("1. Meters to Kilometers")
print("2. Kilometers to Meters")
print("3. Centimeters to Inches")
print("4. Inches to Centimeters")
choice = int(input("Enter choice: "))
value = float(input("Enter value: "))
if choice == 1:
print(f"{value} m = {value / 1000} km")
elif choice == 2:
print(f"{value} km = {value * 1000} m")
elif choice == 3:
print(f"{value} cm = {value / 2.54} in")
elif choice == 4:
print(f"{value} in = {value * 2.54} cm")
def weight_converter():
print("\nWeight Conversion Options:")
print("1. Kilograms to Grams")
print("2. Grams to Kilograms")
print("3. Pounds to Kilograms")
print("4. Kilograms to Pounds")
choice = int(input("Enter choice: "))
value = float(input("Enter value: "))
if choice == 1:
print(f"{value} kg = {value * 1000} g")
elif choice == 2:
print(f"{value} g = {value / 1000} kg")
elif choice == 3:
print(f"{value} lbs = {value * 0.4536} kg")
elif choice == 4:
print(f"{value} kg = {value / 0.4536} lbs")
def temp_converter():
print("\nTemperature Conversion Options:")
print("1. Celsius to Fahrenheit")
print("2. Fahrenheit to Celsius")
print("3. Celsius to Kelvin")
print("4. Kelvin to Celsius")
choice = int(input("Enter choice: "))
value = float(input("Enter value: "))
if choice == 1:
print(f"{value}°C = {(value * 9/5) + 32}°F")
elif choice == 2:
print(f"{value}°F = {(value - 32) * 5/9}°C")
elif choice == 3:
print(f"{value}°C = {value + 273.15} K")
elif choice == 4:
print(f"{value} K = {value - 273.15}°C")
def main():
while True:
print("\n=== Unit Converter ===")
print("1. Length")
print("2. Weight")
print("3. Temperature")
print("4. Exit")
option = int(input("Choose option: "))
if option == 1:
length_converter()
elif option == 2:
weight_converter()
elif option == 3:
temp_converter()
elif option == 4:
print("Exiting...")
break
else:
print("Invalid option!")
main()