Hey guys, welcome to Day 14 of 100 Days of Code. Today
you are going to spend building an exciting game called Higher or Lower.
And if you want to have a go at it, just go over to higher
lowergame.com and click on classic.
So the classic version of higher lower is you compare one search term,
The Grand Budapest hotel
which is a movie, against another search term AFL,
which is the American Football League.
And you have to say if the second one has higher or lower searches
than the Grand Budapest hotel. So I think this probably has higher.
And indeed I'm right. And then now it gives you a new term to compare.
So Six Nations Rugby versus AFL who has lower.
I think this probably has lower and I'm right.
And you keep going until you get it wrong.
And it's a weirdly addictive game for some reason. Okay.
So now I've gotten it wrong and it tells me how many I got right as my score
and I can play again if I wish to. Have a play around with that game
because the final version we have looks a lot simpler,
but it's still just as fun to play.
Instead of comparing average monthly searches on Google,
we're comparing who has more followers on Instagram.
So we're bringing this game up to date. In this case, it's comparing Neymar,
a footballer from Brazil against Chloe Kardashian, a reality TV
personality and businesswoman from the US who has more followers.
So I think it's 'B', I could be wrong and I'm wrong.
So here we're comparing
Rihanna a musician and businesswoman from Barbados against Shakira
a musician from Columbia.
So I'm going to guess probably Rihanna and I get it right,
so I get to score one point. And this game continues on and on until you get to
the point where you get it wrong, same as the one that you saw before.
And there we go. So I got three as my final score,
and that's the end of the game.
The aim of the game is to try and stay alive for as long as possible and score
as high as possible by thinking about who might be more popular than the other.
Now here comes the interesting part.
You are going to be coding up this game entirely by yourself.
You're going to apply everything you've learned so far to understand how this
game works by playing it quite a few times,
going to this URL and looking at all the specific nuances;
what happens if you get it wrong, what happens if you get it right,
and you're gonna write the code all yourself,
and you're probably going to need your skills of debugging to fix some problems
as you go along as well.
So the approach I want you to take is first think about the problem and then
break down a large problem into smaller problems.
This way you can tackle them one by one, and it won't be so intimidating.
Now, step 2 is to look at those problems and make a
to-do list. Given the items on the to-do list,
you're going to pick the one that you think is the easiest to begin.
Let's say that, uhm, maybe generating a random number.
That's pretty simple, right? Well, in this to-do list,
that's the first one we're going to tackle. So in this case,
we're building a very simple dice game, right?
The game that you were going to be building is a lot more complex,
it won't just have three to-dos. But the idea is the same.
Once you pick the task that you think is the easiest, generating a random number,
then you gotta take that problem
and you're going to break it down into comments in your code.
So just as you've seen me do it for our previous project,
you are going to do the same thing.
You're going to take that problem of generating a random number and then split
it into different pieces, right?
First, you probably have to import the random module and then you probably have
to use a function like randint to generate
a random integer. So now that you've taken a big problem and broken it apart into
smaller problems, taking the easier smaller problem
and break it down into comments in your code,
then you are ready to start writing some code.
So write code beneath the comments, run your code,
make sure that it does what you want it to do. And if it doesn't, then fix the code.
And once you've done that, then it's back to the beginning,
write more code under the comments, run more code,
fix more code until you've managed to cross out that task.
And then its a case of tackling the next one that you think you can attempt.
So this is the real skill of programmers; taking something that's immensely
complex and difficult, breaking it down into smaller problems,
breaking it down further,
and then tackling them from the easiest to the hardest and doing this one by
one. Eventually by the end, you end up with your final product.
This is what I want you to do.
So the first thing you have to do is the head over to the final version of the
game,
play it at least 10 times just so you understand exactly how it works and then
pull up the starting code for the day, which is the higher-lower-start,
and go ahead and fork your own copy of it.
Now you'll notice that there's three files in the starting code. One is the art
.py that contains the logo and the versus symbol that shows up when it asks you
to compare.
So compare A, Christiano Ronaldo versus B, Vin Diesel.
And these are the art that you're going to display. And finally,
and probably most importantly, there is a file called game data. Now game data
only a single variable.
It's a list of dictionary entries.
Each of these dictionaries have four keys and the keys are the same for
all of the entries. They've got a name, the name of the account,
the follower count,
so how many followers in millions does that account have.
So for example, Christiano Ronaldo has 215 million followers,
at least at the time when I compiled the data. And then it has a description,
he's a footballer or this is a social media platform,
she's a musician and actress. And finally the country that they're from.
You're going to use all of these pieces of information to construct a comparison
line like this, compare A: Cristiano Ronaldo
a football from Portugal. We have B.
And you're going to ask the user to guess who has more followers. And if they get
it right, they get to keep playing, where A now becomes the previous B,
so Vin Diesel who you used to be B now becomes A,
and then you get to compare against a new person and it keeps on going until they
get it wrong. That is the task ahead of you
and it's not going to be easy, but I think you can do it.
So give this project at least an hour. You'll need to write the code,
you will need to fix problems, you'll need to debug,
you will need to test it quite a few times. But by the end of it,
you will emerge a stronger programmer
I promise. So good luck and make sure you have lots of struggle and I'll see you
on the other side.