Temperature Converter

Convert between Celsius, Fahrenheit, and Kelvin.

Logic BuildingIntermediate
Logic Building
# Take input
temp = float(input("Enter temperature: "))
unit = input("Enter unit (C/F/K): ").upper()

# Convert to all units
if unit == 'C':
    celsius = temp
    fahrenheit = (celsius * 9/5) + 32
    kelvin = celsius + 273.15
elif unit == 'F':
    fahrenheit = temp
    celsius = (fahrenheit - 32) * 5/9
    kelvin = celsius + 273.15
elif unit == 'K':
    kelvin = temp
    celsius = kelvin - 273.15
    fahrenheit = (celsius * 9/5) + 32
else:
    print("Invalid unit")
    exit()

print(f"Celsius: {celsius:.2f}°C")
print(f"Fahrenheit: {fahrenheit:.2f}°F")
print(f"Kelvin: {kelvin:.2f}K")

Output

Enter temperature: 25
Enter unit (C/F/K): C
Celsius: 25.00°C
Fahrenheit: 77.00°F
Kelvin: 298.15K

Convert between temperature scales.

Key Concepts:

  • F = (C * 9/5) + 32
  • K = C + 273.15
  • Convert based on input unit