Temperature Converter

A Python application to convert between Celsius, Fahrenheit, and Kelvin temperature units.

Project Details

Temperature Converter Project

About This Project

This is a simple temperature conversion tool built in Python. It allows you to convert between different temperature units:

  • Celsius to Fahrenheit
  • Fahrenheit to Celsius
  • Kelvin to Celsius
  • Kelvin to Fahrenheit
  • Fahrenheit to Kelvin
  • Celsius to Kelvin
Python Command Line Utility

Python Code

# Temperature converter def clear(): # import OS is not available in Skulpt, pretend this clears the output # def clear(): # if os.name == 'nt': # os.system('cls') # else: # os.system('clear') pass def main(): while True: CorF = input("\nSelect one:\n1: °C to °F\n2: °F to °C\n3: K to °C\n4: K to °F\n5: °F to K\n6: °C to K\n7: Exit\n") clear() if CorF in {"1", "2", "3", "4", "5", "6", "7"}: try: if CorF == "7": break else: temp = float(input("What is the temperature?\n")) clear() if CorF == "1": # °C to °F print("Your temperature is ", temp * 1.8 + 32, "°F") elif CorF == "2": # °F to °C print("Your temperature is ", (temp - 32) / 1.8, "°C") elif CorF == "3": # K to °C print("Your temperature is ", temp - 273.15, "°C") elif CorF == "4": # K to °F print("Your temperature is ", (temp - 273.15) * 1.8 + 32, "°F") elif CorF == "5": # °F to K print("Your temperature is ", (temp - 32) / 1.8 + 273.15, "K") elif CorF == "6": # °C to K print("Your temperature is ", temp + 273.15, "K") except ValueError: input("Invalid input! Please enter a valid numerical temperature.\nPress enter to continue...") clear() continue else: input("Invalid input! Please enter a number from 1 to 6.\nPress enter to continue...") clear() continue if input("Would you like to convert another temperature? (Y/N)\n").lower() == "y": clear() else: clear() input("Thank you for using my converter!\nPress enter to exit...") break if __name__ == "__main__": main()

Output

Click "Run Code" to see the program output here
Waiting for input...

How It Works

This program uses the following temperature conversion formulas:

Celsius to Fahrenheit

°F = (°C × 9/5) + 32

Fahrenheit to Celsius

°C = (°F - 32) × 5/9

Kelvin to Celsius

°C = K - 273.15

Celsius to Kelvin

K = °C + 273.15

The program uses a simple command-line interface to get user input and display the converted temperature values.