-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask 1.txt
More file actions
40 lines (32 loc) · 1.29 KB
/
Copy pathTask 1.txt
File metadata and controls
40 lines (32 loc) · 1.29 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
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
def celsius_to_kelvin(celsius):
return celsius + 273.15
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
def fahrenheit_to_kelvin(fahrenheit):
return (fahrenheit - 32) * 5/9 + 273.15
def kelvin_to_celsius(kelvin):
return kelvin - 273.15
def kelvin_to_fahrenheit(kelvin):
return (kelvin - 273.15) * 9/5 + 32
def main():
print("Temperature Converter")
value = float(input("Enter the temperature value: "))
unit = input("Enter the unit of measurement (C, F, K): ").strip().upper()
if unit == 'C':
fahrenheit = celsius_to_fahrenheit(value)
kelvin = celsius_to_kelvin(value)
print(f"{value} °C = {fahrenheit:.2f} °F and {kelvin:.2f} K")
elif unit == 'F':
celsius = fahrenheit_to_celsius(value)
kelvin = fahrenheit_to_kelvin(value)
print(f"{value} °F = {celsius:.2f} °C and {kelvin:.2f} K")
elif unit == 'K':
celsius = kelvin_to_celsius(value)
fahrenheit = kelvin_to_fahrenheit(value)
print(f"{value} K = {celsius:.2f} °C and {fahrenheit:.2f} °F")
else:
print("Invalid unit of measurement. Please enter C, F, or K.")
if __name__ == "__main__":
main()