Wait, we use the equal sign twice?
Yep, the equal sign was used before to assign the number 5 to our variable secret. Then we use two equal signs to compare the variables secret and guess.
Why are there spaces in front of print? Because we need to tell the computer that the print happens under the if statement, instead of happening all the time. If we wanted to print more things or do other things if we guessed the correct number, then we could line up the next command under print. We call this print statement indented when it has spaces before it.
But it would be better if the computer told us if we got our guess wrong. That's where else comes in: Else happens when the if comparison is false. See that there are no spaces before else. This is because it doesn't happen when we guess the number, but when we don't. The print statement here is also indented.
1
2
No comments:
Post a Comment