Problem: Write a program that gives the age of a person using the datetime library class in Python. If the input date is not correct, print the word “WRONG” in the output. Date format is yyyy/mm/dd. (For example, if it enters 15 for the month, because we only have 12 months, it should print “WRONG” in the output. The same applies to the number of days, and the maximum is 31).
NB: The input and output of the following example is related to the execution of the program on 02/01/2019.
Sample input: 1995/02/03
Sample output: 24
Many Thanks in advance
Is this some kind of homework assignment or are you asking for help on one of the exercises from the course?
If you would like to help on solving this problem, please let me know.
You did not answer my question. There is an ethical problem just giving you the answers for a homework assignment, etc which does not apply if you are just working on one of the exercises for the Mosh course.
Yes you’re right. But I do not have any courses from Mosh and subscribed to [Code with Mosh Forum] to ask for help for my problems which are either my exercises in university class or my routine task at the moment.
Then maybe you should narrow your question. What are you having problems with? Do you have a partial program setup and some part of it is not working as you expected?
a hint is that you can use if statement to finish this and set different variables for each year/month/date like date = something, then combine them when printing like
print(date + month + year)
and set the max value separately for each variable
Note: for number of days, the maximum is actually different for each month (and you may have to take into account the year for the maximum number of days in February). For example, any of the following would be invalid: September 31, February 29 (2022), February 30 (any year).
Your problem statement also did not clarify what it should print out if there are no validation errors.
thanks for also mentioning that, you can also maybe try and use the date or time ( I dont remember the exact name) module too