0% found this document useful (0 votes)
15 views2 pages

Pro 3

Uploaded by

soyeb patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Pro 3

Uploaded by

soyeb patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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):
celsius = fahrenheit_to_celsius(fahrenheit)
return celsius_to_kelvin(celsius)

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

def temperature_converter():
print("Welcome to the Temperature Converter!")
print("Select the conversion you want to perform:")
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")
print("7. Exit")

while True:
choice = input("Enter your choice (1-7): ")

if choice == '7':
print("Exiting the converter. Goodbye!")
break

if choice in ['1', '2', '3', '4', '5', '6']:


try:
temp = float(input("Enter the temperature to convert: "))
except ValueError:
print("Invalid input! Please enter a numeric value.")
continue

if choice == '1':
print(f"{temp}°C is {celsius_to_fahrenheit(temp)}°F.")
elif choice == '2':
print(f"{temp}°F is {fahrenheit_to_celsius(temp)}°C.")
elif choice == '3':
print(f"{temp}°C is {celsius_to_kelvin(temp)}K.")
elif choice == '4':
print(f"{temp}K is {kelvin_to_celsius(temp)}°C.")
elif choice == '5':
print(f"{temp}°F is {fahrenheit_to_kelvin(temp)}K.")
elif choice == '6':
print(f"{temp}K is {kelvin_to_fahrenheit(temp)}°F.")
else:
print("Invalid choice! Please select a valid conversion.")

# Run the temperature converter


temperature_converter()

You might also like