Python Forum
Programme will not returns the day number not the day name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Programme will not returns the day number not the day name
#7
You can take advantage of using dict in order to avoid long/multiple if/elif/else
def day_of_the_week(n):
    week = {'0':'Sunday',
            '1':'Monday',
            '2':'Tuesday', 
            '3':'Wednesday',
            '4':'Thursday',
            '5':'Friday',
            '6':'Saturday'}
    return week.get(n, 'Invalid number')

n = input("Enter a number 0 to 6: ")
print(f'The day of the week is {day_of_the_week(n)}')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Programme will not returns the day number not the day name - by buran - Jul-27-2020, 11:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How returns behave in a function with multiple returns? khasbay 1 314 May-19-2024, 08:48 AM
Last Post: deanhystad
  Why am I getting this error from Dave Beazly's programme? Pedroski55 4 544 Apr-26-2024, 12:31 PM
Last Post: Pedroski55
  Call a bash script from within a Python programme Pedroski55 6 2,661 Dec-06-2021, 01:53 PM
Last Post: DeaD_EyE
  Can you tell me if this python programme will get me in trouble with my organisation? abstraction 8 3,950 Feb-25-2019, 12:13 PM
Last Post: metulburr
  [Regex] Findall returns wrong number of hits Winfried 8 6,083 Aug-23-2018, 02:21 PM
Last Post: Winfried

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020