Another thing about this game. It's boring. Why? Because we know the secret number. It's five. It's written right at the top of the program. But there is a way to be able to change things, but we have to get it from outside of the built in functions in our programming language: Okay, that's better. Now I have no idea what secret is. In fact, it will change every time I click the Run button. But we had to do some interesting things to get there. First we had to import some code that makes the computer be able to pick a random number. Then we had to use that code by typing a period (.) after random so you could use one of its functions. All random's functions are inside random, and you use a period to get to them. The function we are using is called randint and we give it two numbers to tell it how low and high it can go when picking a number.
One thing. Why is it called int? It's short for integer, which means all whole numbers, positive or negative.
Now let's give the guesser a hint so we know if they need to guess higher or lower: So now we know the answer to what to do if you need something inside a while and inside an if. You indent twice. Also, we have a new comparison. It's a less-than (<) comparison. If you're daring, change the secret random number to between 1 and 100, and see how quickly you can guess it.
1
2
No comments:
Post a Comment