Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Creating Odd and Even Logic | Conditional Statements in Python
Introduction to Python

book
Challenge: Creating Odd and Even Logic

Let's tackle another practice task!

Task

Swipe to start coding

You are given the variables num and result. Using if/else, assign the value to the variable result:

  • If num is odd, assign the string 'odd'.
  • If num is even, assign the string 'even'.

Tip: A number is considered even if, when divided by 2, the remainder (using the % operator) is 0.

Note

In Python, the % operator is used as the modulo operator, which returns the remainder after dividing one number by another. For example, 5 % 2 would return 1, since 2 goes into 5 twice with a remainder of 1.

image

Solution

num = 8941 % 931
result = 'blank'

# Write your code here
if num % 2 == 0:
result = 'even'
else:
result = 'odd'

# Testing
print("The number num is", result)
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 8
num = 8941 % 931
result = 'blank'

# Write your code here
if ___:
result = ___
else:
result = ___

# Testing
print("The number num is", result)
toggle bottom row
some-alt