[Tutor] If, elif, else

Dave Angel davea at davea.name
Wed Jan 29 01:42:25 CET 2014


 "Michael L. Pierre" <Michael.Pierre at ccpoa.org> Wrote in message:
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

Start by posting in text form, since this is a text group.  You
 apparently posted in html. And you doublespaced.
 

Any reason you didn't use the date module?  The code would have
 been much simpler. 

> gotten it resolved to the point that it understands leap  years and gives the correct age. 

Sometimes. 

> My problem arises when a date is input that is the current month, but a future date (i.e. today’s date is 1/28/2014 but the input dob is 1/30/1967)
 It skips over the elif option to subtract one year and prints out
 ***HAPPY BIRTHDAY***

> am only going to paste the non-leap year code, because the leap year code is basically identical.

 Problems from a quick perusal.  

 The first if clause tries to handle the cases where the month is
 different.  But it should only be subtracting 1 if age_month is
 negative. 

Next the elif clause. You subtract month_less but don't initialize
 it to zero.  Why bother subtracting anyway? In this clause
 there's no adjustment needed.

Next the missing elif for int(current_split[2])  < int(dob_split[2]):


-- 
DaveA



More information about the Tutor mailing list