1 00:00:00,030 --> 00:00:04,800 Hey guys, welcome to Day 14 of 100 Days of Code. Today 2 00:00:04,800 --> 00:00:09,450 you are going to spend building an exciting game called Higher or Lower. 3 00:00:10,020 --> 00:00:12,660 And if you want to have a go at it, just go over to higher 4 00:00:12,660 --> 00:00:15,540 lowergame.com and click on classic. 5 00:00:16,110 --> 00:00:20,910 So the classic version of higher lower is you compare one search term, 6 00:00:20,940 --> 00:00:22,230 The Grand Budapest hotel 7 00:00:22,230 --> 00:00:26,010 which is a movie, against another search term AFL, 8 00:00:26,040 --> 00:00:27,690 which is the American Football League. 9 00:00:28,260 --> 00:00:33,210 And you have to say if the second one has higher or lower searches 10 00:00:33,480 --> 00:00:37,050 than the Grand Budapest hotel. So I think this probably has higher. 11 00:00:37,740 --> 00:00:42,480 And indeed I'm right. And then now it gives you a new term to compare. 12 00:00:42,990 --> 00:00:47,100 So Six Nations Rugby versus AFL who has lower. 13 00:00:47,430 --> 00:00:50,250 I think this probably has lower and I'm right. 14 00:00:50,610 --> 00:00:53,490 And you keep going until you get it wrong. 15 00:00:53,670 --> 00:00:57,750 And it's a weirdly addictive game for some reason. Okay. 16 00:00:57,750 --> 00:01:02,460 So now I've gotten it wrong and it tells me how many I got right as my score 17 00:01:02,820 --> 00:01:07,230 and I can play again if I wish to. Have a play around with that game 18 00:01:07,260 --> 00:01:10,740 because the final version we have looks a lot simpler, 19 00:01:10,890 --> 00:01:13,050 but it's still just as fun to play. 20 00:01:13,680 --> 00:01:17,520 Instead of comparing average monthly searches on Google, 21 00:01:17,730 --> 00:01:21,300 we're comparing who has more followers on Instagram. 22 00:01:21,750 --> 00:01:26,130 So we're bringing this game up to date. In this case, it's comparing Neymar, 23 00:01:26,190 --> 00:01:30,210 a footballer from Brazil against Chloe Kardashian, a reality TV 24 00:01:30,240 --> 00:01:34,530 personality and businesswoman from the US who has more followers. 25 00:01:34,770 --> 00:01:39,300 So I think it's 'B', I could be wrong and I'm wrong. 26 00:01:42,740 --> 00:01:43,880 So here we're comparing 27 00:01:44,150 --> 00:01:49,070 Rihanna a musician and businesswoman from Barbados against Shakira 28 00:01:49,100 --> 00:01:50,480 a musician from Columbia. 29 00:01:50,810 --> 00:01:54,800 So I'm going to guess probably Rihanna and I get it right, 30 00:01:54,800 --> 00:01:59,800 so I get to score one point. And this game continues on and on until you get to 31 00:02:01,970 --> 00:02:05,600 the point where you get it wrong, same as the one that you saw before. 32 00:02:06,980 --> 00:02:10,220 And there we go. So I got three as my final score, 33 00:02:10,639 --> 00:02:12,830 and that's the end of the game. 34 00:02:13,340 --> 00:02:18,260 The aim of the game is to try and stay alive for as long as possible and score 35 00:02:18,290 --> 00:02:23,290 as high as possible by thinking about who might be more popular than the other. 36 00:02:23,930 --> 00:02:25,670 Now here comes the interesting part. 37 00:02:25,910 --> 00:02:29,690 You are going to be coding up this game entirely by yourself. 38 00:02:30,320 --> 00:02:35,320 You're going to apply everything you've learned so far to understand how this 39 00:02:35,510 --> 00:02:37,970 game works by playing it quite a few times, 40 00:02:38,240 --> 00:02:42,770 going to this URL and looking at all the specific nuances; 41 00:02:42,770 --> 00:02:45,920 what happens if you get it wrong, what happens if you get it right, 42 00:02:46,490 --> 00:02:49,520 and you're gonna write the code all yourself, 43 00:02:49,970 --> 00:02:54,320 and you're probably going to need your skills of debugging to fix some problems 44 00:02:54,350 --> 00:02:55,730 as you go along as well. 45 00:02:56,360 --> 00:03:01,270 So the approach I want you to take is first think about the problem and then 46 00:03:01,330 --> 00:03:05,080 break down a large problem into smaller problems. 47 00:03:05,560 --> 00:03:09,940 This way you can tackle them one by one, and it won't be so intimidating. 48 00:03:10,480 --> 00:03:14,830 Now, step 2 is to look at those problems and make a 49 00:03:14,830 --> 00:03:17,950 to-do list. Given the items on the to-do list, 50 00:03:18,310 --> 00:03:22,240 you're going to pick the one that you think is the easiest to begin. 51 00:03:22,930 --> 00:03:26,860 Let's say that, uhm, maybe generating a random number. 52 00:03:26,890 --> 00:03:30,100 That's pretty simple, right? Well, in this to-do list, 53 00:03:30,130 --> 00:03:33,190 that's the first one we're going to tackle. So in this case, 54 00:03:33,190 --> 00:03:36,040 we're building a very simple dice game, right? 55 00:03:36,160 --> 00:03:38,770 The game that you were going to be building is a lot more complex, 56 00:03:38,770 --> 00:03:41,560 it won't just have three to-dos. But the idea is the same. 57 00:03:41,770 --> 00:03:46,720 Once you pick the task that you think is the easiest, generating a random number, 58 00:03:47,110 --> 00:03:48,880 then you gotta take that problem 59 00:03:49,030 --> 00:03:52,450 and you're going to break it down into comments in your code. 60 00:03:52,900 --> 00:03:56,740 So just as you've seen me do it for our previous project, 61 00:03:57,010 --> 00:03:58,300 you are going to do the same thing. 62 00:03:58,390 --> 00:04:02,320 You're going to take that problem of generating a random number and then split 63 00:04:02,320 --> 00:04:04,660 it into different pieces, right? 64 00:04:04,690 --> 00:04:08,440 First, you probably have to import the random module and then you probably have 65 00:04:08,440 --> 00:04:11,260 to use a function like randint to generate 66 00:04:11,290 --> 00:04:16,290 a random integer. So now that you've taken a big problem and broken it apart into 67 00:04:16,870 --> 00:04:20,380 smaller problems, taking the easier smaller problem 68 00:04:20,649 --> 00:04:23,110 and break it down into comments in your code, 69 00:04:23,440 --> 00:04:25,690 then you are ready to start writing some code. 70 00:04:26,500 --> 00:04:30,820 So write code beneath the comments, run your code, 71 00:04:31,120 --> 00:04:35,110 make sure that it does what you want it to do. And if it doesn't, then fix the code. 72 00:04:35,530 --> 00:04:37,930 And once you've done that, then it's back to the beginning, 73 00:04:37,960 --> 00:04:41,140 write more code under the comments, run more code, 74 00:04:41,170 --> 00:04:45,880 fix more code until you've managed to cross out that task. 75 00:04:46,330 --> 00:04:50,140 And then its a case of tackling the next one that you think you can attempt. 76 00:04:50,530 --> 00:04:54,700 So this is the real skill of programmers; taking something that's immensely 77 00:04:54,700 --> 00:04:58,090 complex and difficult, breaking it down into smaller problems, 78 00:04:58,390 --> 00:04:59,710 breaking it down further, 79 00:04:59,740 --> 00:05:04,000 and then tackling them from the easiest to the hardest and doing this one by 80 00:05:04,000 --> 00:05:08,170 one. Eventually by the end, you end up with your final product. 81 00:05:08,650 --> 00:05:10,330 This is what I want you to do. 82 00:05:10,900 --> 00:05:14,620 So the first thing you have to do is the head over to the final version of the 83 00:05:14,620 --> 00:05:15,400 game, 84 00:05:15,400 --> 00:05:20,400 play it at least 10 times just so you understand exactly how it works and then 85 00:05:21,100 --> 00:05:25,960 pull up the starting code for the day, which is the higher-lower-start, 86 00:05:26,560 --> 00:05:29,410 and go ahead and fork your own copy of it. 87 00:05:30,280 --> 00:05:35,280 Now you'll notice that there's three files in the starting code. One is the art 88 00:05:35,860 --> 00:05:40,860 .py that contains the logo and the versus symbol that shows up when it asks you 89 00:05:41,950 --> 00:05:42,880 to compare. 90 00:05:43,810 --> 00:05:48,040 So compare A, Christiano Ronaldo versus B, Vin Diesel. 91 00:05:48,640 --> 00:05:51,640 And these are the art that you're going to display. And finally, 92 00:05:51,910 --> 00:05:56,770 and probably most importantly, there is a file called game data. Now game data 93 00:05:56,800 --> 00:05:59,180 only a single variable. 94 00:05:59,600 --> 00:06:03,410 It's a list of dictionary entries. 95 00:06:03,890 --> 00:06:08,720 Each of these dictionaries have four keys and the keys are the same for 96 00:06:08,720 --> 00:06:12,920 all of the entries. They've got a name, the name of the account, 97 00:06:13,190 --> 00:06:14,300 the follower count, 98 00:06:14,300 --> 00:06:18,530 so how many followers in millions does that account have. 99 00:06:18,710 --> 00:06:23,690 So for example, Christiano Ronaldo has 215 million followers, 100 00:06:23,900 --> 00:06:28,490 at least at the time when I compiled the data. And then it has a description, 101 00:06:28,580 --> 00:06:31,850 he's a footballer or this is a social media platform, 102 00:06:32,120 --> 00:06:35,960 she's a musician and actress. And finally the country that they're from. 103 00:06:36,230 --> 00:06:41,230 You're going to use all of these pieces of information to construct a comparison 104 00:06:41,750 --> 00:06:44,610 line like this, compare A: Cristiano Ronaldo 105 00:06:44,610 --> 00:06:46,850 a football from Portugal. We have B. 106 00:06:47,360 --> 00:06:52,360 And you're going to ask the user to guess who has more followers. And if they get 107 00:06:53,510 --> 00:06:58,280 it right, they get to keep playing, where A now becomes the previous B, 108 00:06:58,760 --> 00:07:02,960 so Vin Diesel who you used to be B now becomes A, 109 00:07:03,470 --> 00:07:08,470 and then you get to compare against a new person and it keeps on going until they 110 00:07:09,710 --> 00:07:13,340 get it wrong. That is the task ahead of you 111 00:07:13,670 --> 00:07:16,940 and it's not going to be easy, but I think you can do it. 112 00:07:17,330 --> 00:07:21,530 So give this project at least an hour. You'll need to write the code, 113 00:07:21,530 --> 00:07:23,840 you will need to fix problems, you'll need to debug, 114 00:07:24,080 --> 00:07:27,560 you will need to test it quite a few times. But by the end of it, 115 00:07:27,620 --> 00:07:30,110 you will emerge a stronger programmer 116 00:07:30,140 --> 00:07:35,140 I promise. So good luck and make sure you have lots of struggle and I'll see you 117 00:07:35,720 --> 00:07:36,560 on the other side.