This assignment tests your understanding of variables, and their uses. Variables are probably the most important thing in programming. They store the data that your program is using, and without them, it would be very difficult (if not impossible) to write a useful program. If you missed the first assignment, click here for instructions on how to install Python. If you are unable to install Python then you can use replit.com to run your programs on-line.
All programming languages have variables, and lots of them, including Python, are typed, which means that different types of data - e.g. text and numbers - can be stored and processed appropriately.Python has four main types of variable - int (whole numbers), float (floating-point/decimal numbers), str (string, i.e. text) and bool (true or false). You can determine the type of a variable in Python by using the type() command - e.g. if you set a = 1, then type(a) will return int. This can be useful as Python can change the type of a variable while your program is running - that is called casting.
There aren't many restrictions on the names of variables - they can have any combination of letters and numbers, but they cannot start with a number or a character that isn't a letter, and they can't be the same as a Python command, e.g. print. It does make sense for the variable name to suggest what it stores, e.g. name for a name or age for an age.
You have to give a variable a value before it is used. Giving a variable a value is know as assigning a value. It's very easy to do, and you can use a value or string, or the result of a calculation. All of the following are valid assignments:
age = 10 age = 8 + 2 name = "Joe" fullname = "Joe " + "Bloggs" fullname = forename + " " + surname
You can also use the same variable as part of the assignment - this is useful when adding to, or taking away from, a value:
age = age + 1 fullname = "Mr " + fullname
This might look confusing at first, but remember that the = sign means to make it equal, not that it is equal, as in Maths. The variable to the left of the = sign is the new value, and the one on the right is the old value, so age = age + 1 means "make the new value of age equal to the old value plus one".
The following assignments are NOT valid and will result in a type mismatch error because you're trying to mix strings and numbers:
age = "Hello" + 10 name = 10 name = name + "Bloggs"
If you want to read a lot more about variables and variable types, have a look at Variables at Computing and ICT in a Nutshell.