I'm making a simple program that outputs a person's age and days until their birthday and I've run into two problems. My if statement to determine if the birthdate has passed is always using the if portion, not the elif. My if statement at the bottom to display either birthday passed, birthday today, birthday tomorrow, or days until birthday is always using my else statement.
day_after = birth_date + timedelta(days=1)
day_before = birth_date - timedelta(days=1)
# enter code to calc age here
if birth_date.month and birth_date.day > current_date.month and current_date.day:
year_old = current_date.year - birth_date.year
elif birth_date.month and birth_date.day < current_date.month and current_date.day:
year_old = current_date.year - birth_date.year - 1
# code to calc and print days until persons next birthday
days_until_birthday = days_until(birth_date, current_date)
#outputs
print("Birthday: ", birth_date.strftime("%A, %B %d, %Y"))
print("Today:\t", day_only.strftime("%A, %B %d, %Y"))
print(name, "is", year_old, "years old.")
if current_date.day and current_date.month == day_before.day and day_before.month : # birthday is tomorrow
print(name, "'s birthday is tomorrow!")
elif current_date.day and current_date.month == day_after.day and day_after.month: # birthday is yesterday
print(name, "'s birthday was yesterday!")
elif current_date.day and current_date.month == birth_date.day and birth_date.month: # birthday is today
print(name, "'s birthday is today!")
else:
print(name + "'s birthday is in", days_until_birthday, "days!")
my output is:
Birthday Calculator
Enter name: Matthew
Enter birthday (MM/DD/YY): 07/17/91
Birthday: Wednesday, July 17, 1991
Today: Thursday, October 15, 2020
Matthew is 29 years old.
Matthew's birthday is in 274 days!
Continue? (y/n): y
Enter name: Jayden
Enter birthday (MM/DD/YY): 12/19/11
Birthday: Monday, December 19, 2011
Today: Thursday, October 15, 2020
Jayden is 9 years old.
Jayden's birthday is in 64 days!
Continue? (y/n): y
Enter name: Testbirth tomorrow
Enter birthday (MM/DD/YY): 10/16/00
Birthday: Monday, October 16, 2000
Today: Thursday, October 15, 2020
Testbirth tomorrow is 20 years old.
Testbirth tomorrow's birthday is in 0 days!