Variables are a key programming feature. Sometimes the programs we write need to have values that change or need to be stored to recall later on.
We see this often in games.
pictures courtesy of Enter your name! The best name entry screens in gaming | GamesRadar+
In both examples above, we can see where a user is expected to enter their name. For for the scoreboard and one so that the game mechanics can keep referring to it during the game story.
<aside> 💡 Some golden rules when assigning variables:
print
=
. remember that ==
is a comparative operator.high score = 145
✅ high_score = 145
</aside>
So, if wanted to create a variable called score
and assign the value 0
, I would write:
score = 0
If I wanted to output the value, I could write:
print(score)
Take a look at how I can assign and re-assign the variable with a new value.
https://codapi.org/embed/?sandbox=python&code=data%3A%3Bbase64%2CK07OL0pVsFUw4Cooyswr0SgG8TW5uIqh4oYo4gA%3D
https://youtube.com/shorts/epkv6Lg5maM?si=wkl-JkD9Lt-nu9Aq
Write a program with all of the following variables and then print them to the screen.