Python If-Else - Hacker Rank Solution

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

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

Python If-Else

👊 Table Of Contents

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 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 greater than 20, print Not 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

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

Python 3

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")            
Python If else hacker rank solution
Python If-Else

Disclaimer: The above problem is generated by Hackerrank but the solution is given by Sloth Coders. If you have any doubt regarding the problem( Python If- Else ), feel free to contact in the Comment section.

All Solution of Python Hacker Rank Problems are available here - Python Solution

Happy Coding!!

A Sloth Who loves to code.

Also Read:

Sloth Coders is a Learning Platform for Coders, Programmers and Developers to learn from the basics to advance of Coding of different langauges(python, Java, Javascript and many more).

Post a Comment