1 00:00:00,440 --> 00:00:01,220 How was it? 2 00:00:01,220 --> 00:00:03,980 Were you amazed at how soon you'll hit one of these milestones? 3 00:00:03,980 --> 00:00:06,180 I know a couple caught me off guard. 4 00:00:06,180 --> 00:00:07,890 Let's see how I broke this one down. 5 00:00:07,890 --> 00:00:09,460 First, I got to get that name. 6 00:00:09,460 --> 00:00:10,520 That's simple enough. 7 00:00:10,520 --> 00:00:13,470 Just ask for their name and start on the variable. 8 00:00:13,470 --> 00:00:14,120 We've all done that. 9 00:00:15,360 --> 00:00:19,270 So getting the year they were born could be a bit trickier. 10 00:00:19,270 --> 00:00:21,220 We have to make sure they gave us a number. 11 00:00:21,220 --> 00:00:24,049 Now, I'm going to use a while loop, and 12 00:00:24,049 --> 00:00:27,223 then I will have a try and accept inside of it. 13 00:00:27,223 --> 00:00:31,749 Now there is probably a more clever way to solve this especially using something like 14 00:00:31,749 --> 00:00:33,290 strings is numeric method. 15 00:00:33,290 --> 00:00:36,030 But I don't mind doing things that a bit more spelled out like this. 16 00:00:36,030 --> 00:00:39,023 It definitely shows you exactly what is going on. 17 00:00:39,023 --> 00:00:43,280 So now that I have the year they were born, I can figure out how old they are. 18 00:00:43,280 --> 00:00:47,550 I am going to do that by setting the current year to a variable. 19 00:00:47,550 --> 00:00:50,600 Now that does mean I'm going to have to update the script next year, 20 00:00:50,600 --> 00:00:52,740 but whatever, that's fine. 21 00:00:52,740 --> 00:00:55,400 By then, I'll probably know a better way of doing this. 22 00:00:55,400 --> 00:00:58,564 Right now when I'm recording this, it is the year 2017. 23 00:00:58,564 --> 00:01:00,810 So that is what I am going to put for current year. 24 00:01:00,810 --> 00:01:04,630 If you're watching this in the future, hi, and I hope things turned out well. 25 00:01:04,630 --> 00:01:06,210 Then to get their age, 26 00:01:06,210 --> 00:01:10,490 roughly, I'm going to subtract their birth year from the current year. 27 00:01:10,490 --> 00:01:15,000 This doesn't really account for their birthday if it's passed yet or not, but 28 00:01:15,000 --> 00:01:17,880 it's close enough for what we are doing. 29 00:01:17,880 --> 00:01:21,562 Now I have to figure out when they are going to turn a particular age. 30 00:01:21,562 --> 00:01:26,405 To do that I can take whatever age it is that I want to know when they 31 00:01:26,405 --> 00:01:27,870 are going to turn. 32 00:01:27,870 --> 00:01:31,898 I can subtract form that their current age. 33 00:01:31,898 --> 00:01:34,919 And again, there is probably a more clever way of doing this. 34 00:01:34,919 --> 00:01:38,288 But then I'm going to add it to the current year. 35 00:01:38,288 --> 00:01:41,610 So to figure out when somebody if going to turn 25 for example, 36 00:01:41,610 --> 00:01:45,850 I take 25 minus their current age and then I add that to the current year. 37 00:01:45,850 --> 00:01:50,420 So, if they were say 30, this is going to give me negative 5 which means 38 00:01:50,420 --> 00:01:54,400 that current year is going to be before 2017. 39 00:01:54,400 --> 00:01:56,570 And we're going to use that in just a minute. 40 00:01:56,570 --> 00:01:58,200 So I have all the dates that I need. 41 00:01:58,200 --> 00:02:00,030 Now I just need to print things out. 42 00:02:00,030 --> 00:02:05,130 I'll use an if to make sure that each year is greater than the current year. 43 00:02:05,130 --> 00:02:08,760 And if it is, then I'll print out the message to the user. 44 00:02:08,760 --> 00:02:10,095 So here's what that looks like. 45 00:02:10,095 --> 00:02:13,069 If turn 25 is greater than current year, print out something. 46 00:02:13,069 --> 00:02:14,980 Turn 50, so on and so forth. 47 00:02:16,280 --> 00:02:17,720 It's time to try this one out. 48 00:02:17,720 --> 00:02:20,960 So we'll do python age_calc.py. 49 00:02:20,960 --> 00:02:24,330 You can call me Kenneth. 50 00:02:24,330 --> 00:02:25,140 And I was born in 1981. 51 00:02:25,140 --> 00:02:27,960 So there we go. 52 00:02:27,960 --> 00:02:31,110 I didn't get the 25 because I'm past that one. 53 00:02:31,110 --> 00:02:34,090 But I still got 50, 75, and 100. 54 00:02:34,090 --> 00:02:35,900 Nice. I hope you liked this 55 00:02:35,900 --> 00:02:37,280 bit of extra practice. 56 00:02:37,280 --> 00:02:40,520 Be sure to fill out the feedback survey about these kinds of practices and 57 00:02:40,520 --> 00:02:42,780 let us know what else you'd like to practice in the future. 58 00:02:42,780 --> 00:02:45,620 If you have ideas for other types of practice, be sure and 59 00:02:45,620 --> 00:02:46,820 let us know about those, too. 60 00:02:46,820 --> 00:02:47,740 Thanks and I'll see you next time.