Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Problem 2: Write a function that takes as an argument a date in 2023 and returns the day of the week corresponding to that date.

image text in transcribed
Problem 2: Write a function that takes as an argument a date in 2023 and returns the day of the week corresponding to that date. The function should have the following signature: def weekDay(month, day): For example, weekDay (1,28) should evaluate to "Saturday" and weekDay (2, 3) should evaluate to "Friday". You can assume that both arguments month and day are positive integers. But, it is possible that together month and day do not represent a valid date in 2023. In that case, the function should return the empty string ".". For example, weekDay (2,30), weekDay (20,5), and weekDay (10,200) should all evaluate to . Algorithm to use: The algorithm for this function consists of two steps. - Step 1: Given a particular month and day, first find the number of days that have passed since Jan 1st, 2023. For example, if month =2 and day =3, then 33 days have passed since Jan 1 st, 2023 and we are on Day 34 . This quantity can be computed by a call to the previous function number0fDays. - Step 2: Since we are on Day 34, this means that 4 weeks have been completed since Jan 1st, 2023 and we are on Day 6 of Week 5. Now note that Jan 1st, 2023 is a "Sunday". Therefore, Day 6 of a week in the year 2023 is going to be "Friday". This is the string your function needs to return. Step 2 can be accomplished by using a giant ifstatement. Note that your function should return one of the following 8 strings "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", or ". . It should not return anything else and make sure the spelling of the strings is exactly correct. What to submit: Use the starter file wps2,RY and make modifications to it, following the instructions provided

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started