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