Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions temperature_converter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# temperature_converter.py
def celsius_to_fahrenheit(c):
return (c * 9/5) + 32

def fahrenheit_to_celsius(f):
return (f - 32) * 5/9

def celsius_to_kelvin(c):
return c + 273.15

def kelvin_to_celsius(k):
return k - 273.15

def fahrenheit_to_kelvin(f):
c = fahrenheit_to_celsius(f)
return celsius_to_kelvin(c)

def kelvin_to_fahrenheit(k):
c = kelvin_to_celsius(k)
return celsius_to_fahrenheit(c)

if __name__ == "__main__":
temp = float(input("Enter temperature: "))
print(f"{temp}°C is {celsius_to_fahrenheit(temp)}°F")
print(f"{temp}°F is {fahrenheit_to_celsius(temp)}°C")
print("Temperature Converter")
print("Choose the conversion type:")
print("1. Celsius to Fahrenheit")
print("2. Fahrenheit to Celsius")
print("3. Celsius to Kelvin")
print("4. Kelvin to Celsius")
print("5. Fahrenheit to Kelvin")
print("6. Kelvin to Fahrenheit")

choice = input("Enter your choice (1-6): ")

if choice in {'1', '2', '3', '4', '5', '6'}:
temp = float(input("Enter the temperature: "))

if choice == '1':
print(f"{te