Coding Example (M)
Coding Example (M)
import easygui
different variables in terms of the data they hold.
# This checks that the user is an appropriate age (under 14). If they
# are, continue_quiz is set to "Yes". This is used as a gate later on to
# decide whether the user sees the quiz questions or the program exits.
# If the user is older than 13 they are encouraged to do the Youth Quiz
# instead, and are given the option to continue on with the CyberSmart
# Start Quiz or quit. If they decide to continue, continue_quiz is set
# to "Yes".
if user_age < 14:
Literal used rather than constant, making the program less flexible.
continue_quiz = "Yes"
easygui.msgbox("Quiz rules/intro goes here")
# This is the gate to check whether the quiz should continue because
# either the user has earlier indicated they are under 14, or they want
# to continue even though they are older.
if continue_quiz == "Yes":
if player_answer == answer:
easygui.msgbox("Well done, " + player_name + "! You got it right!")