Python bootcamp · Lab 03

Celsius to Fahrenheit

easyMath8 minLesson: Math

Read the question, write Python on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read a temperature in Celsius (it may have a decimal point) and print it in Fahrenheit.

The formula is F = C × 9/5 + 32. Print the result with exactly one digit after the decimal point.

Input. One line: a number (int or float).

Output. Fahrenheit, one decimal place, e.g. 98.6

Constraints

  • -273.15 ≤ C ≤ 1000

Examples

Example 1 — Body temperature.
Input
37
Output
98.6
Example 2 — Water boils. Note the trailing .0 — formatting keeps it.
Input
100
Output
212.0
Hint
  1. Read with float(input()) so decimals survive.
  2. In Python 3, 9 / 5 is 1.8. Using 9 // 5 would truncate to 1 and give the wrong answer.
  3. Format with an f-string: f"{f:.1f}".
Show correct code

Peek only after you have tried. You can still Check your own version.

c = float(input())
print(f"{c * 9 / 5 + 32:.1f}")
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.