+ 3

Code coach: "Day of the week"

You receive a date and need to know what day of the week it is. Task: Create a program that takes in a string containing a date, and outputs the day of the week. Input Format: A string containing a date in either "MM/DD/YYYY" format or "Month Day, Year" format. Output Format: A string containing the day of the week from the provided date. Sample Input: 11/19/2019 Sample Output: Tuesday Can you help me in making logic for this question.? I am using python language.

25th Jul 2023, 1:01 PM
Khan
10 Réponses
+ 11
Khan , some hints how the task can be done: one way we can use is to take the *datetime module* that is supplied with python suppose the given date format is like 11/19/2019: > import the datetime module. > take an input and store it as a string > now we have to parse the input for correctness. this is done with datetime.strptime(...,...) we have to define what each of the 3 parts of the input date means. this is done like '%m/...', which expects a zero padded number for the month (these codes are called format codes). this has to be done with month, day and year. > if the input date and the parameters of datetime.strptime() matches, a datetime object will be created. > we can now use the datetime object and do the output formatting using datetime.strftime(...,...). to get the name of day we can use '%A' format code. find more about the *datetime format codes*: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
25th Jul 2023, 3:08 PM
Lothar
Lothar - avatar
+ 7
Khan , > please do a try by yourself first. save your code in playground and post a link to it here.
25th Jul 2023, 1:58 PM
Lothar
Lothar - avatar
+ 6
Have a look for what calendar packages are available to use in python and see how they work.
25th Jul 2023, 2:02 PM
Ausgrindtube
Ausgrindtube - avatar
+ 4
Niyibizi Protogene , please do *not* post a new question inside an existing post of someone else. it is better for you to start your own post, otherwise poeple will not get aware of you. please also include your current code in the post.
26th Jul 2023, 9:21 PM
Lothar
Lothar - avatar
+ 3
Lothar, Thankyou so much for your help, I will learn more about it and will give it a try. Thanks once again
25th Jul 2023, 4:46 PM
Khan
+ 2
25th Jul 2023, 4:48 PM
Khan
+ 2
Happy Lothar could better explain and help!
25th Jul 2023, 7:03 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
amount= (input () ) this is the code the is complete the code to ensure the value the entered by by the user is stored as an integer help me
26th Jul 2023, 4:39 PM
Niyibizi Protogene
Niyibizi Protogene - avatar
0
Hi
26th Jul 2023, 8:44 AM
Erman Esaliev
Erman Esaliev - avatar
0
Hi
27th Jul 2023, 2:13 AM
Fayaz ktk
Fayaz ktk - avatar