Python bootcamp · Lab 04

Even or odd

easyIf Else8 minLesson: If Else

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

QuestionHint and solution stay closed until you open them

Read one integer and print even or odd (lowercase).

The modulo operator % gives the remainder after division — the classic tool for this.

Input. One line: an integer (may be negative).

Output. The word even or odd.

Constraints

  • Works for negative numbers too.

Examples

Example 1
Input
4
Output
even
Example 2
Input
7
Output
odd
Hint
  1. n % 2 is 0 for even numbers.
  2. A conditional expression is tidy here: "even" if n % 2 == 0 else "odd".
Show correct code

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

n = int(input())
print("even" if n % 2 == 0 else "odd")
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.