mikeckennedy / python-jumpstart-course-demos

Contains all the "handout" materials for my Python Jumpstart by Building 10 Apps course. This includes try it yourself and finished versions of the 10 apps.
https://talkpython.fm/course
MIT License
746 stars 536 forks source link

Incorrect output in Birthday app #8

Closed zabkov closed 7 years ago

zabkov commented 7 years ago

It is incorrect to use int() for calculating days from seconds, there should be math.ceil() Now is 3/30/2017, input is 3/31/2017, and the app says that today is the birthday

redeemefy commented 7 years ago

I think that one of the purposes of the app is to expose the student to the datetime module. When I did the app I encounter something similar. But part of the learning process is to go to the documentation and figure out what other options the datetime module has. Turns out that the module has a date method. So you can say instead...

    current_date = date.today()
    dt = user_birth_date - current_date
    return dt.days

The date.today() will give you year, month, and day without hours, minutes, seconds. With that you will have no problem calculating yesterday or tomorrow delta times.

mikeckennedy commented 7 years ago

Hi @diazgilberto thanks so much for posting this. Yes, I totally spaced on today() vs now() during the recording. I'm going to go back and update the video. It's one of those things of speaking, presenting, and coding all at the same time and just letting that detail slip by...

mikeckennedy commented 7 years ago

And, thanks @zabkov for posting the original issue!

redeemefy commented 7 years ago

@mikeckennedy You did great. It is one of those things where makes the student go out and research on their own. Also, the lecture taught me how to refactor my code to get the outcome I want. The student can see the process of development; code, test, refactor and repeat.

mikeckennedy commented 7 years ago

Hi guys. Got a chance to re-record the videos and fixed this. Thanks for reporting it.

redeemefy commented 7 years ago

👍