Temperature Converter
Convert between Celsius, Fahrenheit, and Kelvin.
IntermediatePhase 6 - Category 5: Real-World Logic ProblemsExample 6 of 15
temperature-converter.py
1# Take input2temp = float(input("Enter temperature: "))3unit = input("Enter unit (C/F/K): ").upper()45# Convert to all units6if unit == 'C':7 celsius = temp8 fahrenheit = (celsius * 9/5) + 329 kelvin = celsius + 273.1510elif unit == 'F':11 fahrenheit = temp12 celsius = (fahrenheit - 32) * 5/913 kelvin = celsius + 273.1514elif unit == 'K':15 kelvin = temp16 celsius = kelvin - 273.1517 fahrenheit = (celsius * 9/5) + 3218else:19 print("Invalid unit")20 exit()2122print(f"Celsius: {celsius:.2f}°C")23print(f"Fahrenheit: {fahrenheit:.2f}°F")24print(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
What's going on
Convert between temperature scales.
Key Concepts:
F = (C * 9/5) + 32
K = C + 273.15
Convert based on input unit
🔗Related Content
- 📖
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- 💻
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum