PYTHON
VARIABLES OBJECTIVES Challenge - Understand what Variables are and what they are used for Super Challenge - Apply your understanding of Variables so you have puzzles and objects in your game STARTER Get your brains working |
KEYWORDS
|
VARIABLES
You have already learnt what variables are when you did inputs - Look through your books to remind yourself how you store inputs.
You can also use variables to store whether the user has chosen to pick up an object e.g. a key
You will need to store the variable as GLOBAL so that all of the program recognises it, not just the function it's been used in. Look below to see an example
global Key
def GettingKey(): # declaring a function
Key = input("you see a shiny key on the floor do you want to pick it up y/n?") # storing whether user picks up the key as y or n
TASK
Look through your game code so far, identify where you might need to user to store clues or objects and add a variable to store whether or not they do. Remember to make the variable global.
EXTENSION
Instead of using Variables look at how to use Lists (also called arrays)
http://www.pythoncode.co.uk/adventure-rucksack
You have already learnt what variables are when you did inputs - Look through your books to remind yourself how you store inputs.
You can also use variables to store whether the user has chosen to pick up an object e.g. a key
You will need to store the variable as GLOBAL so that all of the program recognises it, not just the function it's been used in. Look below to see an example
global Key
def GettingKey(): # declaring a function
Key = input("you see a shiny key on the floor do you want to pick it up y/n?") # storing whether user picks up the key as y or n
TASK
Look through your game code so far, identify where you might need to user to store clues or objects and add a variable to store whether or not they do. Remember to make the variable global.
EXTENSION
Instead of using Variables look at how to use Lists (also called arrays)
http://www.pythoncode.co.uk/adventure-rucksack