Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Examples
  3. Celsius to Fahrenheit

Operators · Python example

Celsius to Fahrenheit

Convert a temperature with a formula and formatted output.

Open the compilerAll examples
beginnerconversionarithmetictemperature

Temperature conversion is a short exercise in operator precedence and float formatting.

example.py
celsius = 37
fahrenheit = (celsius * 9 / 5) + 32

print(f"{celsius}°C = {fahrenheit:.1f}°F")

How the code works

  • 37 × 9 / 5 is 66.6.
  • Adding 32 gives 98.6.
  • The f-string inserts both temperatures.

Key ideas

  • Multiplication and division happen before addition.
  • 9 / 5 produces a float.
  • The result is formatted to one decimal place.

Try changing it

  • Convert the other way: (fahrenheit - 32) × 5 / 9.
  • Print a table of temperatures from 0 to 100.
  • Read the value with float(input()).

Related examples

beginner

Add Two Numbers

Store two integers in variables and print their sum with an f-string.

beginner

Calculate Simple Interest

Use arithmetic operators and formatted floats to compute interest.

Previous exampleFloyd's TriangleNext exampleWrite and Read a Text File

Expected output

37°C = 98.6°F

Output is compared after trimming trailing whitespace on each line. Run the code to see it produced by CPython in your browser.

Practice next

Apply the same idea with automatic tests or browse a guided project.

ExercisesProjects