1. Python If-Else (HackerRank problem with solution)

Python If-Else (HackerRank problem with solution)

Problem-1




Solution:-(using Python 3)

if __name__ == '__main__':
    '''if __name__ == '__main__': is a universal condition which is
    used to run program as by default in built-in system value of
     __name__ = '__main__' it can be checked by print(__name__) code'''

    n = int(input().strip())
    #using .strip() is s good practice for removing blank spaces

    if (n%2==0 and (n in range(2,6) or n>20) and (n in range(0,101))):
        print("Not Weird")

    elif (n%2==0 and n in range(6,21) and (n in range(0,101))):
        print("Weird")

    elif (n in range(1,101)):
        print("Weird")

    else:
        print("Number is out of range")

Comments