Skip to content
ExamSpine

Lesson 2.3 · Write it

Even or odd

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 whole number and prints whether it is even or odd.

  1. If the number is even, print the number followed by is even.
  2. If the number is odd, print the number followed by is odd.
  3. Print exactly one of those two lines, never both. Spaces at the end are ignored.
  4. The number can be 0 or negative.

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

In Python, use int to convert. A number is even when its remainder after dividing by 2 is 0. 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.

  • an even number (rule 1)

    You type

    1. typed: 4

    It prints

    4 is even
  • an odd number (rule 2)

    You type

    1. typed: 7

    It prints

    7 is odd
  • zero is even (rules 1 and 4)

    You type

    1. typed: 0

    It prints

    0 is even
solution.pySolution.java