vendredi 17 juillet 2020

Python if statements-hackerrank

Here is the question from challenges: If is odd, print Weird If is even and in the inclusive range of 2 to 5 , print Not Weird If is even and in the inclusive range of 6 to 20, print Weird If is even and greater than 20 , print Not Weird

My code: if name == 'main': n = int(input().strip())

if (n%2==1):  #print Weird for odd number
    print("Weird")
 
else if(n%2==0 for n in range(6,21)):  #to print Weird as output for numbers between 6 to 20 
    print("Weird")

else if(n%2==0 for n in range(2,6)):   #to print No weird for even number between 2 to 5
    print("Not Weird")
  
else if(n>20 and n%2==0):  #to print Not Weird for even greater than 20 
    print("Not Weird")

i am getting a wrong output for 24. Instead of showing Not Weird,i am getting Weird as output.Can you guide me where i gone wrong.

Aucun commentaire:

Enregistrer un commentaire