# Python programming problem 2

**URL:** <https://forum.codewithmosh.com/t/python-programming-problem-2/14305>\
**Category:** Python\
**Created:** [August 11, 2022, 12:00pm UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305 "2022-08-11T12:00:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adpy](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@adpy](https://forum.codewithmosh.com/u/adpy)\
**Post date:** [August 11, 2022, 12:00pm UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/1 "2022-08-11T12:00:45Z")

</div>

🙂 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

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [August 11, 2022, 4:08pm UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/2 "2022-08-11T16:08:55Z")

</div>

Is this some kind of homework assignment or are you asking for help on one of the exercises from the course?

---

<div class="post-metadata">

**Author:** ![adpy](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@adpy](https://forum.codewithmosh.com/u/adpy)\
**Post date:** [August 11, 2022, 4:46pm UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/3 "2022-08-11T16:46:15Z")

</div>

If you would like to help on solving this problem, please let me know.

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [August 11, 2022, 5:00pm UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/4 "2022-08-11T17:00:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adpy](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@adpy](https://forum.codewithmosh.com/u/adpy)\
**Post date:** [August 12, 2022, 7:39am UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/5 "2022-08-12T07:39:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [August 12, 2022, 4:00pm UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/6 "2022-08-12T16:00:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![D0ll4R](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/d0ll4r/32/4511_2.png) [@D0ll4R](https://forum.codewithmosh.com/u/D0ll4R)\
**Post date:** [August 17, 2022, 7:37pm UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/7 "2022-08-17T19:37:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [August 17, 2022, 7:48pm UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/8 "2022-08-17T19:48:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![D0ll4R](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/d0ll4r/32/4511_2.png) [@D0ll4R](https://forum.codewithmosh.com/u/D0ll4R)\
**Post date:** [August 18, 2022, 11:29am UTC](https://forum.codewithmosh.com/t/python-programming-problem-2/14305/9 "2022-08-18T11:29:09Z")

</div>

thanks for also mentioning that, you can also maybe try and use the date or time ( I dont remember the exact name) module too
