# If Else Hackerrank Solution In Python

Published November 1, 2023 by Jarvis Silva

Looking for the Hackerrank if else solution in Python? You are at the right place. In this article, I will share the if else Hackerrank solution in python.

Hackerrank is a popular online platform which has many programming challenges and competitions which allows developers to participate into them and improve their programming skill.

## Python If Else Hackerrank Question

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

You can find the full question of this problem here: Hackerrank if else question.

Before moving to the solution you should definately try to do this on your own it is very easy but still if you can’t solve it don’t worry you can check the below solution and understand this program.

## Python If Else Hackerrank Solution

``````
#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
n = int(input().strip())

if n % 2 != 0:
print("Weird")
elif n % 2 == 0 and n > 2 and n <= 5:
print("Not Weird")
elif n % 2 == 0 and n > 6 and n <= 20:
print("Weird")
else:
print("Not Weird")
```
```

Above is the python solution for if else Hackerrank challenge, you can submit the above code in hackerrank and it should show you congratulations you solved this challenge.

This was for this article, I hope you found what you were looking and if you want more hackerrank solutions then visit here: Hackerrank python solutions.

Thank you for reading, Happy coding 😊

Free courses and programming resources

Join Telgram