Temperature Converter in Python
Unit conversion practices arithmetic and formatted numeric output.
What is Temperature Converter?
Unit conversion practices arithmetic and formatted numeric output.
Convert Celsius to Fahrenheit.
When should you use it?
- Learn Python syntax through a practical example.
- Build a foundation for larger programming problems.
- Test an idea quickly without a local setup.
Example code
main.py
celsius = 25.0
# Apply the Celsius-to-Fahrenheit formula.
fahrenheit = celsius * 9 / 5 + 32
print(f"{celsius:.1f} C = {fahrenheit:.1f} F")
Expected output
25.0 C = 77.0 F
How it works
The conversion multiplies by nine fifths and then adds 32.
Change the values and run the program in the CodeUtility online Python compiler without installing Python locally.
Practice exercises
Modify the runnable example with the exercises below to build understanding beyond copying the result.
- Change the input and predict the output before running.
- Handle empty or invalid input.
- Wrap the logic in a function and add more test cases.