""" Felix Muzny DS 2000 Lecture 3 September 13, 2024 Updates to improve: - gets all number inputs from the user - uses a constant for the days in the year a program to say how many days you've been alive! """ # constants always go IN_CAPITALS at the top of the file! DAYS_IN_YEAR = 365 # you might also want a current year constant CURRENT_YEAR = 2024 def main(): # Strategy: # number of days in first year # plus middle years # plus days this year # plus the leap days # Step 1: greet the user # Felix likes to put an extra space at the ends of input to make it visually # nicer when you are typing the answer # "what is your name?felix" versus "what is your name? felix" # Laney likes to put the special newline character \n so you # type your answer on the next line! name = input("what is your name?\n") name = input("what is your name? ") print("bday calculator for", name) # Step 2: get numerical information from the user -- # birthyear, birthday number, today day number # if we don't convert the type of input() to an int, later we'll get: # TypeError: unsupported operand type(s) for -: 'int' and 'str' birthyear = int(input("what year were you born? ")) birthday_number = int(input("what number day of the year were you born on? ")) today_number = int(input("what number day of the year is it today? ")) # number of days in first year # subtract 1 because we want to count the first day that you # were alive! first_year_days = (DAYS_IN_YEAR - birthday_number - 1) # calculate the number of middle years # subtract 1 from current year because the # number of "middle years" is age - 1 # example: you were born in 2021: # 2024 - 2021 - 1 = 2 # 2021: first_year_days # 2022: full year (1st middle year) # 2023: full year (2nd middle year) # 2024: today_number middle_years = ((CURRENT_YEAR - 1) - birthyear) # prompt number for leap years because the case when the # user was born in a leap year is difficult! # don't include this year because we haven't "lived" the # leap day yet! (think about why) leap_days = int(input("how many leap years from your birth year through last year? ")) # add everything together total_days = first_year_days + (middle_years * DAYS_IN_YEAR) + today_number + leap_days print("total days alive:", total_days) # don't forget to call main()! # this should be the *only* code outside of main :) main()