This programming assignment will work with decision structur
This programming assignment will work with decision structures and exception handling. Write a program that accepts a date as a string in the form mm/dd/yyyy and outputs whether or not the date is valid. For example, 05/24/1962 is valid, but 09/31/2000 is not (because September has only 30 days). For reference:
• April, June, September, and November all have 30 days
• January, March, May, July, August, October, and December all have 31 days • February has 28 days (we won’t worry about leap years)
If the user does not enter the input in the correct format a ValueError is raised. Write a program that satisfies the following requirements:
Ask the user for a date as a string in the form mm/dd/yyyy.
Print whether or not the date is valid.
Iftheuserentersanincorrectlyformatteddate,printout\"Input was not correctly formatted. Please enter a date in the form mm/dd/yyyy\"
If some other error occurs, print out \"Something went wrong, sorry!\"
Document the program using Python comments.
Some helpful hints:
The input string \"mm/dd/yyyy\" can be split into the month, day, and year using the string split method (splitting at the /).
The in keyword can be used to check if the mm entered is in one of the sets listed above.
When comparing the dd portion of the date to the number of days in the month, remember
to use eval to turn the string dd into a number.
Here are a couple of sample runs for the program.
Solution
Required program is :
def main() :
datestring =input(\"Please enter a date in form mm/dd/yy :\"
date=datetime.strptime(datetring, \'%m%d%y\')
except valueerror :
Print(\" Invaid date entered :\")
