Python Temperature Converter
def / returnPractice

Function: Celsius → Fahrenheit

Write celsius_to_fahrenheit(c) using the formula (c * 9/5) + 32. Functions make formulas reusable and named — a cornerstone of clean code.

Picture this: formula in a function

Put the conversion in def so you can call it for any number.

°Cinput
→
× 9/5 + 32formula
→
°Freturn

In easy words: What is this task?

You write a function that changes a Celsius value into Fahrenheit using a fixed formula.

Where this is used

Used in weather apps, IoT dashboards, health devices, and global systems that support multiple temperature units.

Theory: formula functions

  • Wrap any formula in a function so it has a clear name and can be tested independently.
  • Python returns floats from / division — use round() for clean output.
  • Kelvin = Celsius + 273.15 — another simple formula function.

Real world: weather dashboard

A weather app receives API data in Celsius but US users expect Fahrenheit. celsius_to_fahrenheit() is called for every temperature card — one function, used a thousand times per page load.

Live temperature gauge

20°
Celsius
68°
Fahrenheit
293°
Kelvin
1def celsius_to_fahrenheit(c):
2return (c * 9/5) + 32
20

Example Program

1def celsius_to_fahrenheit(c):
2return (c * 9/5) + 32
3print(celsius_to_fahrenheit(20))