PYTHON
FUNCTIONS OBJECTIVES Challenge - Understand what functions are and how they look in Python Super Challenge - Apply your understanding of functions to your game STARTER Get your brains working |
KEYWORDS
|
FUNCTIONS
You can think of these as similar to SUBROUTINES - they are separate bits of coding that you call on when you need them.
def brainGame(): # declaring a function
answer=input("how many people get off the boat alive") #getting the user to input an answer
if answer =="don't know") #using section to check their answer
print("must try harder") #outputting a response
if gameplay=="yes"#checking if the user has said yes to playing the game
brainGame(): #CALLING the function so it runs
TASK
Practice this in python by working through the 'number guessing game' on page 51 of the red books
Super challenge
Can you start thinking how you will use functions in your game?
Can you start sketching out the order your functions will need to appear - hint you can only call a function after you've declared it
PLENARY
Class discussion - how will functions will work in your game
You can think of these as similar to SUBROUTINES - they are separate bits of coding that you call on when you need them.
def brainGame(): # declaring a function
answer=input("how many people get off the boat alive") #getting the user to input an answer
if answer =="don't know") #using section to check their answer
print("must try harder") #outputting a response
if gameplay=="yes"#checking if the user has said yes to playing the game
brainGame(): #CALLING the function so it runs
TASK
Practice this in python by working through the 'number guessing game' on page 51 of the red books
Super challenge
Can you start thinking how you will use functions in your game?
Can you start sketching out the order your functions will need to appear - hint you can only call a function after you've declared it
PLENARY
Class discussion - how will functions will work in your game