Example on Conditional Statements Python

In this class, we do an example on conditional statements in python.

For Complete YouTube Video: Click Here

Example on Conditional Statements

To learn about conditional statements. Click here.

Given an integer.

Perform the following condition.

if n is odd print weird. Here n means given integer.

if n is even and in the inclusive range of 2 to 5. Print Not weird.

if n is even and in the inclusive range of 6 to 20. Print weird.

if n is even and greater than 20. Print weird.

Input Format: A single line containing a positive integer.

Constraints: 1<=n<=100

Output Format: Print weird if the number shows weird. otherwise Not weird.

Example on Conditional Statements Python
Program

From the above program.

First, Take the integer input.

To check the given integer is odd or even we use modulus.

Given integer modulus 2 is zero. The number is even. Otherwise odd number.

From the above question, we understand that if the number is odd. it was given to print weird.

First, check given number is odd or not.

In the first, if condition we check the given number is odd?

If the condition is not satisfied means it’s an even number.

In the elif part check for the range of numbers, the given number belongs to and display the appropriate message.