Check for odd/even numbers using “mod” operation

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Create a program which asks the user to enter a number and checks if the number is odd or even. Use the “mod” operation for this challenge.

Testing examples:

Your program should display the outputs shown in this table for the given inputs provided;

Input Output
265 You entered an odd number!
0 You entered an even number!
-22 You entered an even number!

Languages

Scratch

What it should look like

Click on the green flag to see the expected output of your program.

Recommended blocks
when green flag clicked

ask [Enter a number:] and wait

set [number v] to (answer)

say [You entered an even number!]

say [You entered an odd number!]

if <((number) mod (2)) = [0]> then
else
end
Hints
  • To find out if a number is even or odd, use the “mod” operation to find the remainder after dividing that number by two. If the remainder is zero the number is even (the () mod () operation under “Operators” script returns the remainder from division of two numbers. For example: (17) mod (3) // 2)

Show Scratch solution

Python
Block-based