1 00:00:00,560 --> 00:00:01,160 Welcome back. 2 00:00:01,670 --> 00:00:10,310 So up until now, we've learned about integers, floats, strings and boolean values, so let's try 3 00:00:10,310 --> 00:00:11,950 and tie some of those things together. 4 00:00:12,620 --> 00:00:14,740 Let's imagine your Facebook. 5 00:00:15,380 --> 00:00:20,510 How do you think Facebook works underneath the hood when it comes to your profile? 6 00:00:21,600 --> 00:00:29,100 Well, they would have, let's say, a variable called name, and this will have your name. 7 00:00:30,340 --> 00:00:36,880 And then they'll probably have a variable with your age, let's say fifty and not actually 50, but 8 00:00:36,880 --> 00:00:44,430 I'm pretending to be for this case just so I sound wiser and then let's say relationship status. 9 00:00:45,370 --> 00:00:49,390 So, again, we also have relationship status on Facebook. 10 00:00:50,020 --> 00:00:52,600 And for now, let's say single. 11 00:00:53,620 --> 00:01:01,360 So that's my Facebook profile right there now, if we wanted to perhaps change that, let's say my relationship 12 00:01:01,360 --> 00:01:04,990 status all of a sudden goes from single to it's complicated. 13 00:01:05,500 --> 00:01:06,970 Well, that's an easy fix. 14 00:01:07,510 --> 00:01:10,930 We would just do relationship status equals to. 15 00:01:12,720 --> 00:01:20,690 It's complicated, I remember because of the single quote, we'll have to do backslash. 16 00:01:26,060 --> 00:01:26,750 Complicated. 17 00:01:27,740 --> 00:01:30,440 And now if I print my relationship status. 18 00:01:31,830 --> 00:01:37,320 You'll see that it's been updated to it's complicated, I am no longer single, hooray! 19 00:01:38,650 --> 00:01:44,470 But this is pretty simple, let's do something more complicated and this is going to be a fun exercise, 20 00:01:45,220 --> 00:01:50,020 let's create a program that I guess is your age. 21 00:01:51,210 --> 00:01:56,140 Let's use the input method that we've seen before. 22 00:01:56,850 --> 00:01:59,610 Remember, the input method allows us to type something. 23 00:02:01,040 --> 00:02:08,870 In here and receive it as input so we can assign that to a variable, so let's say this variable is 24 00:02:08,870 --> 00:02:17,330 going to be birth year and that's going to equal the input that's going to ask. 25 00:02:18,420 --> 00:02:22,620 When or what year were you? 26 00:02:28,590 --> 00:02:35,730 Now, from here, I want you to pause the video and try to solve this yourself, how can you make it 27 00:02:36,090 --> 00:02:41,550 so that at the end of this program you're going to get asked what year, where you're born, you're 28 00:02:41,550 --> 00:02:47,820 going to type in your year, and then it's going to print out your age is whatever the ages. 29 00:02:48,750 --> 00:02:51,570 So pause the video, try and solve this on your own. 30 00:02:52,200 --> 00:02:54,660 Mind you, there is a bit of a trick in here. 31 00:02:54,660 --> 00:03:00,900 So if he gets stuck, try to Google around and figure out what the issue may be. 32 00:03:01,590 --> 00:03:07,140 Again, part of being a programmer is trying to solve these problems that you don't know the answers 33 00:03:07,140 --> 00:03:07,350 to. 34 00:03:09,460 --> 00:03:11,350 All right, let me show you my solution. 35 00:03:12,540 --> 00:03:16,410 We have our birth year here that we're going to store in a variable. 36 00:03:17,940 --> 00:03:26,160 And now we're going to calculate the age, I'm going to say age equals well, it's going to equal the 37 00:03:26,160 --> 00:03:35,310 current year, let's say twenty nineteen and then twenty nineteen here is going to get subtracted from 38 00:03:35,460 --> 00:03:38,800 whatever the birth year that you entered. 39 00:03:39,660 --> 00:03:41,850 So let's enter that. 40 00:03:43,160 --> 00:03:47,960 And then we're simply going to say, print your age is. 41 00:03:49,060 --> 00:03:54,340 And we want to use an F string here, so I'm going to add an F here. 42 00:03:56,330 --> 00:03:58,010 And then simply say. 43 00:04:02,750 --> 00:04:03,770 If I run this. 44 00:04:05,630 --> 00:04:07,490 I get what year were you born? 45 00:04:08,000 --> 00:04:10,460 I was born in 1986. 46 00:04:12,140 --> 00:04:19,820 Hmm, we get an error, and if you try this yourself, you may have encountered this error, we get 47 00:04:19,820 --> 00:04:25,790 something called a type error and there's lots of errors that you can get in Python. 48 00:04:26,570 --> 00:04:29,960 Again, we have a section on air, so don't stress too much about it. 49 00:04:30,260 --> 00:04:39,260 But if you read here, it says unsupported operand type S four minus Int and string. 50 00:04:40,530 --> 00:04:44,040 Hmmm, let's try and debug this. 51 00:04:44,220 --> 00:04:48,750 It looks like we're using minus on an integer and a string. 52 00:04:49,510 --> 00:04:56,760 So let me print out here the type of birth year. 53 00:04:57,700 --> 00:05:07,420 If I run this and let's enter in nineteen eighty six, I get class string and this is a little gotcha 54 00:05:07,780 --> 00:05:12,970 because what input does is it asks you for an input. 55 00:05:13,150 --> 00:05:21,640 But that input that I wrote one nine eight six, well that actually gets converted to a string and assigned 56 00:05:21,640 --> 00:05:22,600 to birth year. 57 00:05:23,550 --> 00:05:27,660 So what that means is that we're trying to subtract. 58 00:05:28,850 --> 00:05:32,270 A number or a string from a number. 59 00:05:33,510 --> 00:05:35,280 So how do we solve this issue? 60 00:05:36,550 --> 00:05:44,590 Well, you'd have to turn this into an integer, and this is something that we saw previously, what 61 00:05:44,590 --> 00:05:52,180 we need to do is to convert this into an integer with using the INT function. 62 00:05:53,260 --> 00:05:59,140 So let's try that if I remove this and click run. 63 00:06:00,520 --> 00:06:02,110 I'll say nineteen eighty six. 64 00:06:04,170 --> 00:06:07,590 And look at that, your age is 33. 65 00:06:08,810 --> 00:06:13,940 We've created a program that is able to tell your age based on the year that you were born. 66 00:06:14,780 --> 00:06:21,860 Now, this may have been tricky to you, but it teaches an important concept in programming that is 67 00:06:21,890 --> 00:06:29,690 sometimes you storing data into different data types and sometimes you need those different data types 68 00:06:29,690 --> 00:06:31,280 to interact together. 69 00:06:32,260 --> 00:06:38,770 So you'll see a lot of problems where you have to convert a data type and this is a very common one 70 00:06:38,920 --> 00:06:45,010 where you take an input that's a string and then you convert it to something like an integer. 71 00:06:46,100 --> 00:06:53,090 So he can perform a mathematical operation, and that's why if you remember, we gave you a list of 72 00:06:53,090 --> 00:06:58,760 all our data types in Python, the fundamental data types, and all of them were blue because, well, 73 00:06:58,760 --> 00:07:03,290 each one of these are actions are functions that we can use. 74 00:07:04,270 --> 00:07:13,180 For example, I converted the birth year into integer, but I could have also converted this to a float, 75 00:07:13,330 --> 00:07:21,340 for example, and if I run this, it would still work because Python knows that, well, we can use 76 00:07:21,340 --> 00:07:27,380 integers and floats in mathematical operation, but you can see here that it's converted into a float. 77 00:07:27,510 --> 00:07:30,940 Now, if we convert this into a boolean. 78 00:07:31,950 --> 00:07:33,240 And I click run. 79 00:07:36,420 --> 00:07:40,720 Your age is twenty eighteen, that's really confusing, right? 80 00:07:40,920 --> 00:07:48,780 Well, that's because this gets turned into true and underneath the hood, python does something weird 81 00:07:48,780 --> 00:07:57,040 where a true value is converted to one because boolean remember, it's one or zero, true or false. 82 00:07:57,930 --> 00:07:58,350 All right. 83 00:07:58,560 --> 00:08:00,770 Hopefully this didn't confuse you too much. 84 00:08:00,780 --> 00:08:02,980 It's something that will encounter throughout the course. 85 00:08:02,980 --> 00:08:05,400 So don't worry, we'll get more and more practice. 86 00:08:06,090 --> 00:08:11,100 However, I hope you get to practice this a little bit to really understand what's going on, because 87 00:08:11,100 --> 00:08:17,580 although this is a couple of lines of code, the principles that we use here, we're going to use throughout 88 00:08:17,580 --> 00:08:19,170 bigger and bigger code bases. 89 00:08:20,200 --> 00:08:21,680 So I guess I'll see you in the next one. 90 00:08:22,120 --> 00:08:22,480 Bye bye.