Once a procedureA section of computer code that performs a specific task. is named and written, it can be callingStarting or running a function or procedure. at any point in the programSequences of instructions for a computer..
To call a procedure in PythonA high-level programming language., simply use its name (include the brackets):
Suppose you wanted to print out player information at the following points in a game:
at the end of a level
when the player loses a life
when the player beats the high score
when the game is over
Each time you needed to print out the player information, you could simply call the procedure:
def update_display():
print("Your score: " + str(score))
time.sleep(1)
print("High score: " + str(high_score))
time.sleep(1)
print("Lives remaining: " + str(lives))
time.sleep(1)
# End of level
update_display()
# Lose a life
update_display()
# New high score
update_display()
# Game over
update_display()
Using this procedure greatly reduces the amount of code that has to be included in the program.