The datetime module
datetime module is an inbuilt module in Python which provides us to solve various problems related to date and time.
The basic syntax of try-except statement:
try:
#statement
except:
#statement
- If the code or statement provided in the try block has no exception then only try executed.
- If any exception occurs in the block of try then try block skipped and except block will be executed.
Algorithm to solve this problem:
- Initially, we will include the datetime module by using the import function.
- Take the date in the form of the date, month, year.
- Since we know that, we going to check the date is valid or not and if the date is valid then ok but when it's invalid, we will ValueError. So, here we will use the try-except statement.
- If the try statement has no exception then we will print the given date is valid otherwise we will print the given date is invalid.
Let's see the implementation of the above algorithm in the Python program.
Output
need an explanation for this answer? contact us directly to get an explanation for this answer