Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22514

Trying to get python to print out corect birth year in this form

$
0
0

I am very new to python, have asked one other question here that worked well so thank you everybody for that,

This issue, I know what I am doing wrong just not sure how to fix it...

the code:

# import current year to ensure code is up-to-datefrom datetime import datecurrent_yr = date.today().year# get name as a stringuser_name = input('What is your name?''''\n')# get age as an intuser_age = int(input('How old are you?''''\n'))birthday_question = input('Have you had your birthday yet?''''\n')# calculate birth yearbirth_year = (current_yr - user_age)birth_year1 = (current_yr - 1 - user_age)# print greetingmy_file = open("my_file.txt", "w+")if {birthday_question} == 'yes':    my_file.write(f'Hello {user_name}! You were born in {birth_year}.')else:    my_file.write(f'Hello {user_name}! You were born in {birth_year1}.')

Is coming up with the same birth year regardless of the answer to birthday_question, and I believe it is because by changing the variable to current_yr - user_age its changing the answer and just not going with the if else statement...

Just not sure how to correct the code, and have tried almost everything I could think of trying,

Thanks for any help

Justin

tried re doing the code to make it simplertried the if else statement abovetried doing if else statement as a variable set etc


Viewing all articles
Browse latest Browse all 22514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>