-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.py
More file actions
25 lines (20 loc) · 739 Bytes
/
Copy pathtemp.py
File metadata and controls
25 lines (20 loc) · 739 Bytes
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
# Choose the unit of temperature conversion
unit = input("Choose the unit of temperature conversion (C/F): ").strip().upper()
#take input(Temperature) from the user
temp = float(input("Enter the temperature: "))
# Function to convert Celsius to Fahrenheit
def temp_c_to_f(c):
return (c*9/5) + 32
# Function to convert Fahrenheit to Celsius
def temp_f_to_c(f):
return (f - 32) * 5/9
# Check the chosen unit and perform the conversion
if unit == "C":
converted_temp = temp_c_to_f(temp)
print(f"{temp}°C is equal to {converted_temp}°F")
elif unit == "F":
converted_temp = temp_f_to_c(temp)
print(f"{temp}°F is equal to {converted_temp}°C")
else:
print("Invalid unit. Please choose 'C' or 'F'.")
exit()