The code wont print out the answer if the user says 'yes'

from datetime import date

birthdate = int(input("What year were you born?"))


def age(birthdate):
    today = date.today()
    return today.year - birthdate -1
print ("have you had your birthday?")
user = input(" ")
if user == 'no' or 'No':
    print("you are ", age(birthdate))
    print("i hope you have a good one")
else:
    print("you are ", age(birthdate +1))
    print("I am sure that was a good day!")

You need if user == 'no' or user == 'No':

You can also combine the input() and print() into one. Do you know how to do that?

thanks for that it worked. no i forgot :frowning:

In the same way as you did at the top:
user = input("Have you had your birthday? ")

To add:

There’s also a way that you can check if the birthday has passed or not. See if you can work that out and post back if you get stuck.

oh sweet thank you. i ran into another problem i wanted to add 1 extra number if the answer is yes but i couldn’t

i tried to do a else:
print("you are ", age(birthdate +1))

This is a very common mistake.

Python reads so like English that people often think that this will work:

if user == 'no' or 'No':

But it does not. You should write this instead:

if user == 'no' or python == 'No':

Even better is this version:

if user.casefold() == 'no':

which will accept ‘no’, ‘NO’, ‘nO’ and ‘No’.

that worked too cheers.

The issue is here:
print("you are ", age(birthdate +1))

What that does is to add one to the birthdate before that number is passed to your function. It’s an easy fix and I’m sure you can fix that, now that you know where the issue is.

i figured it out before i saw your reply i should have been more patient and tried different ways thanks a lot

really appreciated

No worries. Have a good day.

1 Like