HackerRank- Python If-Else




Problem- 2

Given an integer, , 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



  1. import math
  2. import os
  3. import random
  4. import re
  5. import sys
  6. if __name__ == '__main__':
  7. n = int(input().strip())
  8. if n%2!=0:
  9. print('Weird')
  10. elif n%2==0 and n in range(2,5):
  11. print('Not Weird')
  12. elif n%2==0 and n in range(6,20):
  13. print('Weird')
  14. elif n%2==0 and n>20:
  15. print('Not Weird')
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube