Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 23395

codingdirectional: Return the day in a week with python

$
0
0

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"
    else:
        return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][index]
        

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


Viewing all articles
Browse latest Browse all 23395

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>