Search code examples
pythonnumbersdayofweek

Python print day name of week from number


I'm creating a program which I have to put a number and when I run the program, the solution should be the day for that number. But I don't know how to do. The program I did was this:

num = 4
if(num = 1)
    print('Monday')
elif(num = 2)
    print('Tuesday')
elif(num = 3)
    print('Wednesday')
elif(num = 4)
    print('Thursday')
elif(num = 5)
    print('Friday')
elif(num = 6)
    print('Sunday')
elif(num = 7)
    print('Saturday')
elif(num < 1)
    print('Put a number between 1 and 7')
else(num > 7)
    print('Put a number between 1 and 7')

Solution

  • In python, for statements like if, for, etc. You have to add : at the end of it. And for comparing (for equal) you have to use == and not =

    num = 4
    if(num == 1):
        print('Monday')
    elif num == 2:
        print('Tuesday')
    
    .....
    

    You can compare without parenthesis and it will work too.