Problem Set 10: Even or odd number

When you start a new problem set, your first instinct might be to open your computer and begin typing code right away. While this can feel productive, it often leads to frustration when things don't work as expected. Instead, take a few minutes to slow down and plan.

Here are some helpful strategies:

  1. Understand the problem clearly
    • Read the instructions carefully — twice if needed.
    • Ask yourself: What exactly is being asked?
  2. Break the problem into smaller steps
    • Think about the smallest possible actions the computer will need to perform.
    • For example: If the task is to find the first recurring letter in a word, what steps must happen first?
  3. Try solving it on paper first
    • Write out your steps in plain language (pseudocode).
    • Test your steps with a simple example before touching the keyboard.
  4. Translate your steps into code
    • Start small — write only a few lines at a time and test often.
    • Don't worry about perfection at first; get a working version, then improve it.
  5. Check your solution
    • Run it with different examples, including edge cases.
    • Ask: Does this solve the problem in all situations?

  • Read the question carefully (twice).
  • Break the task into the smallest steps.
  • Sketch or write pseudocode before coding.
  • Start small — test as you go.
  • Check your solution with different cases.

Problem Description

Numbers can be even or odd:

  • An even number is any number that can be divided by 2 with no remainder (for example: 2, 4, 10).
  • An odd number is any number that has a remainder of 1 when divided by 2 (for example: 3, 7, 11).

Your task is to write a program that checks if a number is even or odd.

 

Learning Goals

By completing this problem, you should be able to:

  • Use input and output in your program.
  • Apply the modulus operator (<strong>%</strong>) to test divisibility.
  • Use if / else statements to make decisions in your code.
  • Test your program with different values to check accuracy.

 

Tasks

Task 1: Basic Even/Odd Check

  • Write a program that:
    • Asks the user to enter a number.
    • Uses the modulus operator (%) to check if the number is even or odd.
    • Prints either "The number is even" or "The number is odd".

 

Task 2: Handle Zero

  • Update your program so that if the user enters 0, the program prints:
    • "0 is even."

 

Task 3: Handle Negative Numbers

  • Update your program so that it works correctly even if the user enters negative numbers.
  • Example:
    • -4 → Even
    • -7 → Odd

 

Task 4: Test Cases

Run your program with these numbers and write down what your program prints:

  1. 0 → Even
  2. 1 → Odd
  3. 2 → Even
  4. 15 → Odd
  5. -8 → Even
  6. -13 → Odd

 

Extension Challenge (Optional)

Add extra features to your program:

  • After showing the result, ask the user if they want to check another number.
  • If yes, run the program again.
  • If no, print "Goodbye!" and end the program.

 

Success Criteria:

  • You can explain the difference between even and odd numbers.
  • Your program uses % and if / else correctly.
  • Your program works for positive, negative, and zero inputs.
  • (Extension) Your program can run multiple times until the user decides to quit