In this problem, a particular date will be provided by the user which may be from the past or future and we have to find the weekday. To this, we will use the calendar module which provides us various functions to solve the problem related to date, month and year. Before going to find the weekday of a given particular date, we have to check whether the given date is valid or not. If the given date is not valid then we will get some error. So, to overcome this type of error we will use the try-except statement.
Syntax of try-except statement:
try:
#statement
except error_types:
#statement
Algorithm to solve this problem:
- Import calendar module in the program.
- Take a date from the user in the form of date(d) - month(m) -year(y).
- Check the given date is valid or not.
- If the date is valid then execute the next statement.
- If date is invalid then show ‘you have entered an invalid date' to the user.
- Print the weekday of the given date.
Let's start writing the Python program by the implementation of the above algorithm.
Code:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer