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