-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtemperature_converter.py
More file actions
62 lines (55 loc) · 1.94 KB
/
temperature_converter.py
File metadata and controls
62 lines (55 loc) · 1.94 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
#Temperature Conversion
print('Welcome to this Temperature Conversion Program')
name = input('What is your name?').title().strip()
print('Hello '+name+'!')
# Giving Choices
print("Enter 1 if you want to convert from Celsius")
print("Enter 2 if you want to convert from Fahrenheit")
print("Enter 3 if you want to convert from Kelvin")
#Taking input
while True:
x = input('Enter your choice.. : ')
y=int(x)
# Logic to convert when Celsius is Given
if y==1:
temp = input('Given temperature in Celsius: ')
temp_c=int(temp)
temp_f = (9/5*temp_c)+32
temp_k = temp_c + 273.15
temp_f = round(temp_f, 4)
temp_c = round(temp_c, 4)
temp_k = round(temp_k, 4)
print('\nDegrees Celsius:\t\t'+str(temp_c))
print('Degrees Fahrenheit:\t\t'+str(temp_f))
print('Degrees Kelvin:\t\t\t'+str(temp_k))
#Logic to solve when Fahrenheit is Given
elif y==2:
temp = input('Given temperature in Fahrenheit: ')
temp_f = int(temp)
temp_c = (5/9)*(temp_f-32)
temp_k = temp_c+273.15
temp_f = round(temp_f, 4)
temp_c = round(temp_c, 4)
temp_k = round(temp_k, 4)
print('\nDegrees Fehrenheit:\t\t'+str(temp_f))
print('Degrees Celsius:\t\t'+str(temp_c))
print('Degrees Kelvin:\t\t\t'+str(temp_k))
#Logic to solve when Kelvin is Given
elif y==3:
temp = input('Given temperature in Kelvin: ')
temp_k = int(temp)
temp_c = temp_k-273.15
temp_f = (9/5*temp_c)+32
temp_f = round(temp_f, 4)
temp_c = round(temp_c, 4)
temp_k = round(temp_k, 4)
print('\nDegrees Kelvin:\t\t\t' + str(temp_k))
print('Degrees Celsius:\t\t' + str(temp_c))
print('Degrees Fahrenheit:\t\t' + str(temp_f))
else:
print('Incorrect value')
for_quit = input('Enter y to quit')
if for_quit == 'y':
quit()
else:
continue