We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
So many questions, but first....Why didn't my code work on this exercise? Now I know I probably chose a horrible Big O notation, but besides that I really thought it would have worked and I can't see why the application is failing me. Please explain becuase I want to understand. Thanks
num = int(input("Enter a number: "))
n = num % 2
if n == 0 and num >= 2 <=5:
print('Not Weird')
elif n == 0 and num >= 6 <=20:
print('Weird')
elif n == 0 and num > 20:
print("Not Weird")
elif n % 2 != 0:
print('Weird')
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Python If-Else
You are viewing a single comment's thread. Return to all comments →
So many questions, but first....Why didn't my code work on this exercise? Now I know I probably chose a horrible Big O notation, but besides that I really thought it would have worked and I can't see why the application is failing me. Please explain becuase I want to understand. Thanks
num = int(input("Enter a number: ")) n = num % 2 if n == 0 and num >= 2 <=5: print('Not Weird') elif n == 0 and num >= 6 <=20: print('Weird') elif n == 0 and num > 20: print("Not Weird") elif n % 2 != 0: print('Weird')