Python If-Else

January 16, 2024

Task Given an integer, , perform the following conditional actions:

  • 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

x = int(input())
if (x % 2) == 0:
    if x >= 2 and x <= 5:
        print("Not Weird")
    if x >= 6 and x <= 20:
        print("Weird")
    if x > 20:
        print("Not Weird")
else: 
    print("Weird")
n = int(input())
if n % 2 == 0:
    if n in range(2,5):
        print('Not Weird')
    elif n in range(6,21):
        print('Weird')
    elif n > 20:
        print('Not Weird')
else:
    print('Weird')
if __name__ == '__main__':
    n = int(input().strip())
    
    if (n % 2) == 0:
        if (n >= 2) and (n <=5):
            print("Not Weird")
        elif (n >= 6) and (n <=20):
            print("Weird")
        elif (n > 20):
            print("Not Weird")
    else: 
        print("Weird")

Last updated