+ 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.
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
+ 7
Khan ,
> please do a try by yourself first.
save your code in playground and post a link to it here.
+ 6
Have a look for what calendar packages are available to use in python and see how they work.
+ 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.
+ 3
Lothar, Thankyou so much for your help, I will learn more about it and will give it a try. Thanks once again
+ 2
Ausgrindtube Thanks
+ 2
Happy Lothar could better explain and help!
+ 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
0
Hi
0
Hi