Hacker Rank Program Python If-Else

Shubham Hanmant Pawar
1 min readFeb 6, 2024

--

Link: https://www.hackerrank.com/challenges/py-if-else/problem

Explanation:

If n is odd:

Print “Weird”.

Odd numbers are those which are not divisible by 2, meaning they have a remainder when divided by 2.

If n is even and in the inclusive range of 2 to 5:

Print “Not Weird”.

Even numbers within the range of 2 to 5 inclusive are considered “Not Weird”.

If n is even and in the inclusive range of 6 to 20:

Print “Weird”.

Even numbers within the range of 6 to 20 inclusive are considered “Weird”.

If n is even and greater than 20:

Print “Not Weird”.

Even numbers greater than 20 are considered “Not Weird”.

Code:

#!/bin/python3
import math
import os
import random
import re
import sys



if __name__ == '__main__':
n = int(input().strip())
if n %2 ==0:
if n in range(2,5) or n>20:
print('Not Weird')
else:
print('Weird')
else:
print('Weird')

Now you can hit the run code option and then you can hit the submit code option.

So this is all about the hacker rank program Python If-Else. Let’s connect in the next article.

Thankyou !!!

#vevcodelab

http://vevcodelab.com

Best training institute

--

--

No responses yet