-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path23 temperature conversion.py
More file actions
27 lines (24 loc) · 999 Bytes
/
23 temperature conversion.py
File metadata and controls
27 lines (24 loc) · 999 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
26
27
#----- 23 program to convert temperatures to and from Celsius, Fahrenheit -----
def main():
while True:
try:
print('Enter an option from the menu: \n1. Fahrenheit to celcius\n2. Celcius to Fahrenheit')
option = int(input('---------------------------------------------------------------\n'))
if option == 1:
f2c()
elif option == 2:
c2f()
break
except:
print('Invalid entry, enter again.')
def f2c():
print('---------------------------------------------------------\nFahrenheit to Celcius ')
temp = float(input('enter temperature : '))
ctemp = (32 * temp - 32) * 5/9
print('Temperature in celcius :' , ctemp)
def c2f():
print('----------------------------------------------------------\nCelcius to Fahrenheit ')
temp = float(input('enter temperature : '))
ftemp = (temp * 9/5) + 32
print('Temperature in fahrenheit :' , ftemp)
main()