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
53 changes: 53 additions & 0 deletions temp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32

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

def celsius_to_kelvin(celsius):
return celsius + 273.15

def kelvin_to_celsius(kelvin):
return kelvin - 273.15

def fahrenheit_to_kelvin(fahrenheit):
return celsius_to_kelvin(fahrenheit_to_celsius(fahrenheit))

def kelvin_to_fahrenheit(kelvin):
return celsius_to_fahrenheit(kelvin_to_celsius(kelvin))

def temperature_converter():
print("Welcome to the Temperature Converter!")
print("Choose a 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 = int(input("Enter your choice (1-6): "))

if choice == 1:
celsius = float(input("Enter temperature in Celsius: "))
print(f"{celsius}°C is {celsius_to_fahrenheit(celsius)}°F")
elif choice == 2:
fahrenheit = float(input("Enter temperature in Fahrenheit: "))
print(f"{fahrenheit}°F is {fahrenheit_to_celsius(fahrenheit)}°C")
elif choice == 3:
celsius = float(input("Enter temperature in Celsius: "))
print(f"{celsius}°C is {celsius_to_kelvin(celsius)}K")
elif choice == 4:
kelvin = float(input("Enter temperature in Kelvin: "))
print(f"{kelvin}K is {kelvin_to_celsius(kelvin)}°C")
elif choice == 5:
fahrenheit = float(input("Enter temperature in Fahrenheit: "))
print(f"{fahrenheit}°F is {fahrenheit_to_kelvin(fahrenheit)}K")
elif choice == 6:
kelvin = float(input("Enter temperature in Kelvin: "))
print(f"{kelvin}K is {kelvin_to_fahrenheit(kelvin)}°F")
else:
print("Invalid choice! Please choose a number between 1 and 6.")

if __name__ == "__main__":
temperature_converter()