Dark theme

Hopefully you got that working. A few things about this code:

Here we've used the plus operator to concatinate the "---Welcome to the game " and the "name" and then "---".

We could, instead, do this:
print("--- Welcome to the game" , name , "---")
Using the comma prints them together, with a space between.

Note where there are spaces and not spaces in the above compared with what we have. Try this new version. Which works better?


The most important thing about the code, however, is that it uses a variable. A variable is a space in the computer's memory with a label. We can put stuff into the space using the label, for example:
number = 20
Once something is assigned to a label like this, when we use the label, we get the thing:
print(100 - number)

In our case, the variable is called "name". We use it to store the name and print it. An immediate advantage with this is that we could use the variable in hundreds of places, and if we want to change the name throughout the code, we just have to change it in one place, where it is assigned.

However, the real advantage is that we can get our user to enter the name, making our program completely flexible, as we'll see on the next page...

[Home > Part 1 > Next]