Skip to content
ExamSpine

Lesson 2.2 · Write it

Check temperature

A whole programPython or Java6 tests, 3 of them hidden

On a phone? Put the lines in order instead

Write a program that reads a temperature (a whole number) and prints a report.

  1. Always show Temp: followed by the temperature on the first line.
  2. If the temperature is strictly greater than 30, show Hot on the next line.
  3. If the temperature is strictly less than 10, show Cold on the next line.
  4. A temperature between 10 and 30 (inclusive) gets no extra line.
  5. Spaces at the end of a line are ignored.

Your program is run several times. Only what it prints is checked.

In Python, use int to convert the typed line. In Java, use Integer.parseInt.

Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.

Examples

Your program is run 6 times: the 3 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.

  • above 30: the temp and Hot (rules 1 and 2)

    You type

    1. typed: 35

    It prints

    Temp: 35
    Hot
  • below 10: the temp and Cold (rules 1 and 3)

    You type

    1. typed: 5

    It prints

    Temp: 5
    Cold
  • exactly 30: not strictly greater, no Hot (rule 2)

    You type

    1. typed: 30

    It prints

    Temp: 30
solution.pySolution.java