[Tutor] If, elif, else

Michael L. Pierre Michael.Pierre at ccpoa.org
Tue Jan 28 23:46:38 CET 2014


I am a newbie with Python (programming in general) and I am trying to create a program that will take user name and dob and pump out their age, while on a person's birthday the output not only states their name and age, but also prints out ***HAPPY BIRTHDAY***
I have gotten it resolved to the point that it understands leap  years and gives the correct age. 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***
I am only going to paste the non-leap year code, because the leap year code is basically identical.

#Leapyear calculations/decision
if leap_year != int:
    age_month = int(current_split[1]) - int(dob_split[1])
    #print age_month
    if age_month != 0:
        month_less = 1
        age = int(current_split[0]) - int(dob_split[0]) - month_less
        print "you are", age, "years old"
    elif age_month == 0 and int(current_split[2]) > int(dob_split[2]):
        age = int(current_split[0]) - int(dob_split[0]) - month_less
        print "you are", age, "years old"
    else:
       age = int(current_split[0]) - int(dob_split[0])
       print "You are", age, "and today is your birthday ***HAPPY BIRTHDAY***"

Any help would be greatly appreciated :)

Michael Pierre
CCPOA IT Specialist
916-372-6060 Ext. 221


______________________________________________________________________
California Correctional Peace Officers Association Notice of Confidentiality:
This email message, including any attachments, is for the sole use of
the intended recipient(s). These items may contain confidential and/or
privileged information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the intended recipient,
please contact the sender by reply email and destroy all copies of
the original message.
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140128/5a9d13d3/attachment.html>


More information about the Tutor mailing list