Intro to Conditional Statements Day 3 Solution img source : Google

If, else and elif are used to create conditional statement. As the name suggest the conditional statement are used to evaluate a condition. If a condition is evaluated to true a set of code runs else other set of code runs.

Objective
In this challenge, we’re getting started with conditional statements. Check out the Tutorial tab for learning materials and an instructional video!

Task
Given an integer, n, perform the following conditional actions:

  • If n is odd, print Weird
  • If n is even and in the inclusive range 2 of 5 , print Not Weird
  • If n is even and in the inclusive range 6 of 20 to, print Weird
  • If n is even and greater than 20, print Not Weird

Complete the stub code provided in your editor to print whether or not n is weird.

Input Format

A single line containing a positive integer, n.

Constraints

  • 1 <= n <=100

Output Format

Print Weird if the number is weird; otherwise, print Not Weird.

Sample Input 0

3

Sample Output 0

Weird

Solution:

Sample Input 1

24

Sample Output 1

Not Weird

Solution :

n = int(input().strip())
 
if n%2 != 0:
 
print('Weird')
 
if n%2 == 0:
 
if n>=2 and n<=5:
 
print('Not Weird')
 
if n>=6 and n<=20:
 
print('Weird')
 
if n>20:
 
print('Not Weird')

Happy Coding ♥♥

Comment your Own Code ♥

Leave a Reply

Your email address will not be published.