Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 3: Birthday countdown app
Lecture: Dates and times - getting the birthday

Login or purchase this course to watch this video and the rest of the course contents.
0:00 With the general's skeleton or shape of our app in place let's go and fill out some of these pieces simplest want has to be this print header,
0:08 right it's just going to look something like this, the title right the middle and then one more there's so we have our little stamp
0:17 now the next thing that first thing really we're going to do is get the birthday from the user so we could ask them for inputting like a date,
0:26 you know, year slash months last day, but then you've got different cultures have different styles,
0:33 right? Like europe versus the u s we arrange things differently and then the partisan it's hard, so let's just keep it real simple like this,
0:40 we'll just say, when were you born and we'll ask him, what year month and day separately we can use input for that so we can say
0:47 year equals we'll give him a little hint here with this why? Why, why? Why now? I could copy this line for the month or i could just retype it,
0:57 but in PyCharm you can actually hit command d and will be duplicate whatever you
1:02 have selected if there's nothing like that will duplicate the line so it's really nice we
1:05 just say month or here and update this and then again for the day some like that ok, so now we'll have the information when the person was born this is
1:19 not gonna work exactly want to come back and fix this? But before we do let's go a little farther to see why next to one i
1:26 dio is work with dates. You know, just like when we worked with requests, we have to import this module so wouldn't go up here.
1:37 I want to say import daytime so this is a built in a library in Python you have toe install anything extra to get it it's just right there,
1:45 but usually have to import it. So now we come out here and say something like that a birthday i say b
1:52 day some like that equals when come to date time here and now there's a few options what we can do, we can work with date and time so,
2:01 you know, year, month, day, hour, minute second type of thing or we could just work with calendar dates and there's some other options here as well.
2:10 So we come in here if we want to work with daytime that includes the hours minutes, seconds we would work with the time dot date time it's a little
2:18 confusing because, like, why do you say the same word twice? Well, i don't know that's just how they designed it this is the module and
2:24 this is a class contained within their which we can do things like love here and say what's, you know, set the year set the minute things like that,
2:35 we don't care about the time we're trying to compare days, not actual moments in time, so what? We're going to work with dates here?
2:43 We could also we just cared about time you could work with that and what we're also gonna work with implicitly, we won't create one of these,
2:49 but you'll see it, it will be created. But to sort of behind the scenes force is this thing called a time delta,
2:55 which shows you the differences between two dates that's going to be important,
2:58 so we're going to work with data now we're going to try to create the date that they've given us here, so we'll say, and our year, month and day,
3:09 right? So that looks like it's fine. The next thing we want to do is give this back right that's the purpose of this function was to come down here,
3:16 get some, do some or ask the user for this and then actually give back the birthday. So what given stages for term b day and down here or going
3:26 teo, you just change his name really quick just so you can see they don't know no matter from like that so we couldn't hear,
3:34 and we'll return this from this function that we're calling out here and storing this value and use it later in this section here.
3:42 So this almost works now noticed pi charm is highlighting the stuff, and it has a reason for it.
3:48 But let's, go and run and see why he's going to actually be too interesting outcomes here, first of all,
3:54 well, let's, we can't run it because there's no run configuration, so we just right click and say run program,
4:01 and you might expect to see things like this printed out in that and so on
4:05 . But remember, there's no convention what this main method being called has just happens
4:10 to be when i called it so in order for this to actually get triggered to do a thing, we have to come in here and call it now.
4:16 This is not really the best way to trigger this function to be called there's a better way, way we'll get to that another video a little bit later,
4:24 but for now, let's, just do it like this so we can get it to work, and then we'll talk later about how to make it better ah, there we go, birthday app,
4:30 when were we born nineteen, seventy for april fun who that doesn't look very good
4:37 that's not it's not a date i was looking for right so what happened here it says we had a type air that imager is required but what we got was a
4:46 string if i click here to actually take us to where the problem lies who this
4:52 is the thing PyCharm had highlighted it said that you expected editor but you're giving
4:56 me a string and the reason is everything that comes out of input is always a
5:00 strength so we can convert it to a number by just passing that to initialize or for and so when its rapid like this if you wanted a float we would do
5:09 like that but we don't want imagers on something down here okay now we should get
5:16 it to run past this problem it's going to crash in another place but that's okay
5:21 we'll get there well we're making our way down to nineteen seventy four april first and
5:27 now we get this compute dates is not ready that's over here but noticed this part
5:33 works so let's we're not pass it we haven't configured these functions to take those primaries
5:38 yet so it's put that on hold for just a minute let's just print out what we got here we put out our birthday when we were born in one more time
5:46 anything said before april first boom looking at nineteen seven for april first so we've gotten a little ways down the path.
5:54 In our application, we've gone to the user, and we've asked them a couple of questions.
5:58 And we've taken a input and converted it first in numerical values and then to date values. So we're off to a good.

Talk Python's Mastodon Michael Kennedy's Mastodon