+ 1

Simple Python Project.

Question: Using the datetime, calendar and time modules. Your task is to create a program. it should: - take your birthday. - check if current system date is your birthday - if it is, print a happy birthday message. - if it isn't, output how many days until your birthday. okay so i did manage to create the program, and it worked well. link to my project: https://code.sololearn.com/ci3PZ6StRJAb/?ref=app Now here is the problem, my code isn't as clean as it should, as in if i wanted to check if it was someone else's birthday, i would have to change alot of variables. namely: - birth year - birth month - birth day - what number is the "birth day" in a year. Eg 1 Jan is day 1 in a year, and 31 Dec is the 365th day is a year. My birthday March 16 is day 75 this year but if it was a leap year, it would be day 76. soo I'm challenging you to improve my code such that i don't have to change alot of things. Project source @ enki app thank you.

25th Jul 2022, 1:50 PM
David Holmes Ng'andu
David Holmes Ng'andu - avatar
2 Respostas
+ 1
1. Let user input Birthday by year-month-day . Split input by - and map each value to integer. If you wanna keep the dict, then first 3 entries are variables (and the other ones useless) 2. Today is simply datetime.date.today() 3. Calculate bday this year. If bday - today is negative, add 1 to bday.year. To avoid to change too much, you should .... sorry.... begin a new prog. That's the hard life of a coder😔 https://code.sololearn.com/cM3OcQ91PnFa/?ref=app
25th Jul 2022, 6:42 PM
Oma Falk
Oma Falk - avatar