Return the day in a week with python

Hi, I just have a time to solve another python question today. In this example, we are going to develop a method which will receive a number from the user input and returns which day in a week is that numbers refer to. For example, 1 is Sunday and 2 is Monday. If the number is too large or too small then the program will return an error message. Below is the solution to this question, if you have a better solution don’t forget to leave your answer on the below tweet.

def whatday(num):

    index = num -1
    if(index < 0 or index > 6):
        return "Wrong, please enter a number between 1 and 7"
        return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][index]

Like the below tweet or follow me on twitter if you will.

Leave a Reply

Notify of