Guidelines

Remainder Operator %

The remainder operator % divides two numbers and returns the remainder.

For example, 10 % 3 returns 1, which is the remainder when 10 is divided by 3.

Using the Remainder Operator
remainder = 10 % 3 print(remainder) # 1

Applications of the Remainder Operator

The remainder operator is often used to determine if a number is even or odd by checking the remainder when divided by 2.

Determine Even or Odd
# Example of determining even or odd number = 7 # If number is divisible by 2, it's even; otherwise, it's odd if number % 2 == 0: print("It's an even number.") else: print("It's an odd number.")

It can also be used to find the units digit of a number by getting the remainder when divided by 10.

Finding the Units Digit
# Finding the units digit of a number number = 123 ones_place = number % 10 print(ones_place) # 3
Mission
0 / 1

When writing code to determine even and odd numbers using the remainder operator, what is the appropriate code to fill in the blank?

number = 7


if number % 2 == 
:

    print('Even')

else:

    print('Odd')

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result