Content · Programming · Python

Python First Exercises: Convert a Temperature

Temperature conversion is a short exercise in formula translation: turn a mathematical relationship into Python statements. Learn the essential ideas and try a practical example.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Temperature conversion is a short exercise in formula translation: turn a mathematical relationship into Python statements.

Understanding the Concept


Celsius to Fahrenheit uses Fahrenheit = Celsius × 9/5 + 32. Use a floating-point input because temperatures may include decimals. Name the variables after their units so the result cannot be mistaken for the original scale. Arithmetic order matters: Python evaluates multiplication and division before addition.

When and Why You Would Use This


Test values with known reference points. Zero degrees Celsius equals 32 Fahrenheit, and 100 Celsius equals 212 Fahrenheit. Using known outcomes checks both the formula and the operator order.

Practical Example


celsius_temperature = float(input("Temperature in Celsius: "))
fahrenheit_temperature = celsius_temperature * 9 / 5 + 32
print("Fahrenheit:", round(fahrenheit_temperature, 1))

Understanding the Example


Entering 0 prints Fahrenheit: 32.0. Entering 100 prints Fahrenheit: 212.0. The example displays one decimal place in the rounded value, although print may omit trailing zeros in some other contexts.

Example Output


Temperature in Celsius: Fahrenheit: 75.2

Try It Yourself


Extend the program to convert Fahrenheit back to Celsius. Test the pair of conversions with 32 Fahrenheit.

Common Beginner Mistakes


  • Reversing the formula or forgetting the + 32 offset.
  • Using integer-only conversion when fractional temperatures are needed.
  • Not testing the formula against known points such as freezing and boiling temperatures.

Key Takeaways


  • Translate the formula carefully into operator order.
  • Use float for decimal measurements.
  • Check conversions with known reference values.
Share this resourceSend this page to someone who may find it useful.