AyanUpadhaya

Python If-Else Problem Solving HackerRank

Oct 21st, 2021 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. Task
  2. Given an integer n, perform the following conditional actions:
  3.  
  4. Instructions:
  5. If n is odd, print Weird
  6. If n is even and in the inclusive range of 2 to 5, print Not Weird
  7. If n is even and in the inclusive range of 6 to 20, print Weird
  8. If n is even and greater than 20, print Not Weird
  9.  
  10.  
  11. Solve Code:
  12.  
  13. if __name__ == '__main__':
  14.     n = int(raw_input().strip())
  15.  
  16. #If n is even and greater than 20, print Not Weird
  17. if (n%2 == 0 and n>20):
  18.     print("Not Weird")
  19.    
  20. else:
  21.     #odd number testing
  22.     if (n%2 != 0) :
  23.         print("Weird")
  24.     else:
  25.         #If  n is even and in the inclusive range of 2 to 5 , print Not Weird
  26.         if (n%2 == 0) and (n>=2 and n<=5):
  27.             print("Not Weird")
  28.  
  29.         #If n is even and in the inclusive range of 6 to 20, print Weird
  30.         if (n%2 == 0) and (n>=6 and n<=20):
  31.             print("Weird")
Add Comment
Please, Sign In to add comment