Python If-Else | HackerRank Solution

Hello coders, today we will be solving Python If-Else Hacker Rank solution.

Python If-Else - Hacker Rank Solution

Contents

Problem

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

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

Input Format

A single line containing a positive integer, n.

Constraints

 n  100

Output Format

Print Weird if the number is weird. Otherwise, print Not Weird.

Sample Input

3

Sample Output

Weird

Explanation 0

n = 3
n is odd and odd numbers are weird, so print Weird.

Sample Input 1

24

Sample Output 1

Not Weird

Explanation 1

n = 24
n > 20 and is even, so it is not weird. 

Solution – Python If-Else Hacker Rank Solution

n = int(input())
if n % 2 == 1:
    print("Weird")
elif n % 2 == 0 and 2 <= n <= 5:
    print("Not Weird")
elif n % 2 == 0 and 6 <= n <= 20:
    print("Weird")
else:
    print("Not Weird")            

Disclaimer: The above Problem (Python If-Else) is generated by Hacker Rank but the Solution is provided by CodingBroz.

2 thoughts on “Python If-Else | HackerRank Solution”

  1. kalpana pandey

    sir can i code like this….i’m a beginner incoding
    n= int(input())
    if n%2==1:
    print(‘weird’)
    elif n%2==0 and n>20:
    print(‘not weird’)
    elif n%2==0 and n==range(2,5):
    print(‘not weird’)
    elif n%2==0 and n==range(6,20):
    print(‘not weird’)

Leave a Comment

Your email address will not be published.