In this challenge we are putting your deciphering skills to the test.
Here are your secret codes. Will you be able to decode these?
In this challenge we are putting your deciphering skills to the test.
Here are your secret codes. Will you be able to decode these?
When using variables and constants in your programs it is important to use the correct data types.
The main data types are:
You are going to write a Python game where the user walks within the different rooms of a haunted house.
In each room, something will happen. You will decide what happens when the user enters a room. You can use some of the following ideas:
Complete this game, one room at a time:
Here is an example of code for the library() function. Looking at the floor plan of the mansion, you will notice that there is only one door to go back to the hall. However we are going to add a secret passage to lead to the kitchen.
def library():
print("--- You are entering the library ---")
print("")
time.sleep(1)
print("While looking at the books on the bookshelves, you notice that one of the book is not perfectly aligned with the other books.")
print("""
┌─┐
┌─┐ ┌─┐ ┌──┐ │ │
┌──┤ │ │ ├───┤ ├─────┤ │
│ │ ├──┤ │ ├──┤ │ ├───┐
│ ├─┤xx│ │ │┼┼│ ─── │ │ │
│ ├─┤ │ ├───┼──┤ │ │ ┌─┤
│ │ │ │ ├───┤ │ ─── │ │ └─┤
│ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │
└──┴─┴──┴─┴───┤ ├─────┴─┴───┘
└──┘
""")
time.sleep(1)
option = input("Do you: \n a) pick up this book \n b) Leave this book where it is and go back to the hall").lower()
if option == "a":
print("When trying to pick up the book, the book acts as a lever and the bookshelf slides to the left revealing a secret passage.")
time.sleep(1)
print("Feeling adventurous, you decide to go through this secret passage and realise that it leads you to the kitchen.")
time.sleep(1)
kitchen()
elif option == "b":
print("Hum... I do wonder why this book was not perfectly aligned? Anyway, let's go back to the hall...")
time.sleep(2)
hall()
Note that for this code to work, you will also need to define a new function for the kitchen:
def kitchen():
print("--- You are entering the kitchen ---")
print("")
time.sleep(1)
#complete the code here
We will now add an inventory to our code to let the player collect objects as they progress through the game. To do so we will first initialise a new empty list called inventory using the following line of code that we will place at the very beginning of our code (e.g. on line 3)
inventory = []
Then we will add some code to our kitchen() function for the player to pick up a golden key.
In Python, we can check if a value is in a list using the keyword in.
For instance we will only display the key on the floor of the kitchen, if the user has not already picked it up using the following line of code:
if "Golden Key" not in inventory:
To add a value to a list we will use the append() function as follows:
inventory.append("Golden Key")
Let’s use this code to let the user pick up the key from the kitchen floor.
def kitchen():
print("--- You are entering the kitchen ---")
print("")
time.sleep(1)
if "Golden Key" not in inventory:
print("""
┌──────┐
│ │
│ ├────────┬─┬──┬─┐
│ │ │ ├──┤ │
└──────┘ └─┘ └─┘
""")
print("As you enter into the kitchen, you notice a golden key on the floor and decide to pick it up as it could become useful later on.")
inventory.append("Golden Key")
print("Inventory:")
print(inventory)
#Add code here to decide where to go next
Then, in other rooms, you will be able to check if the user has the key to for instance let them open a treasure chest.
def bedroom():
print("--- You are entering bedroom ---")
print("")
time.sleep(1)
print("Hidden under the bed, you find a treasure chest.")
if "Golden Key" in inventory:
print("You use your golden key to open it and found a silver crown inside it.")
inventory.append("Silver Crown")
print("Inventory:")
print(inventory)
else:
print("The treasure chest is locked and you do not seem to have the key to unlock it!")
#Add code here to decide where to go next
Check your computing terminology by joining the dominoes below: (Click on picture to start).
Computing TerminologyOpen Domino Activity

Let’s look at the following code that asks a simple Yes/No question:
answer = input("Are you over 16?")
if answer == "Yes":
print("You can take driving lessons to prepare for your driving test.")
elif answer == "No":
print("You are too young to learn how to drive a car.")
What would happen if:
Now let’s look at how we could improve this code further:
answer = input("Are you over 16?").upper()
if answer == "YES":
print("You can take driving lessons to prepare for your driving test.")
elif answer == "NO":
print("You are too young to learn how to drive a car.")
What do you think will now happen if:
answer = input("Are you over 16?").upper()
if answer == "YES":
print("You can take driving lessons to prepare for your driving test.")
elif answer == "NO":
print("You are too young to learn how to drive a car.")
else:
print("Sorry your answer is not recognised. Restart the program and make sure you answer with the word Yes or the word No.")
What do you think will now happen if:
answer = ""
while (answer!="YES" and answer!="NO"):
answer = input("Are you over 16? (Yes or No)").upper()
if answer == "YES":
print("You can take driving lessons to prepare for your driving test.")
elif answer == "NO":
print("You are too young to learn how to drive a car.")
def askYesNoQuestion(question):
YesNoAnswer = ""
while (YesNoAnswer!="YES" and YesNoAnswer!="NO"):
YesNoAnswer = input(question).upper()
return YesNoAnswer
answer = askYesNoQuestion("Are you over 16? (Yes or No)")
if answer == "YES":
print("You can take driving lessons to prepare for your driving test.")
elif answer == "NO":
print("You are too young to learn how to drive a car.")
def askYesNoQuestion(question):
YesNoAnswer = input(question).upper()
if YesNoAnswer == "YES" or YesNoAnswer == "NO":
return YesNoAnswer
else:
return askYesNoQuestion(question)
answer = askYesNoQuestion("Are you over 16? (Yes or No)")
if answer == "YES":
print("You can take driving lessons to prepare for your driving test.")
elif answer == "NO":
print("You are too young to learn how to drive a car.")
We are trying to build a program that will ask the end-user to choose a flag amongst six flags. The program will then try to guess the selected flag by asking a maximum of two questions.
Look at the flowchart below used to describe our algorithm: (Click on flowchart to open in new window)

![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Using Flowchart Studio, design a similar flowchart used for the computer the guess the correct flag amonst these six new flags. You will need to ask different questions.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |



Have you ever been in a sweet shop to buy sweets? For this challenge we are going to spend £5 in a sweet shop hence we need to find out how many sweets we can afford. We will want to pick and mix sweets until we have spent all our money.
To help us buy our sweets we are going to write a program that will help us decide how many sweets we can afford while allowing us to pick and mix different types of sweets.
Here are the sweets available in the shop:

Here are the main steps of our program which will:
Now let’s see how a flowchart can help us describe these steps further:


A window cleaner uses the following pricing policy to calculate how much to charge for cleaning all the windows of his customer’s dwelling. This pricing policy is based on the number of windows that need to be cleaned and works as follows:
Your task is to write a computer program that prompts the end-user to enter the number of windows of their dwelling. The program will then calculate the quoted price using the pricing policy described above and display it to the end-user.
| Test # | Input values | Expected outcome | Actual outcome |
| 1 | Number of windows: 3 | Cost: £16 | |
| 2 | Number of windows: 5 | Cost: £20 | |
| 3 | Number of windows: 7 | Cost: £23 | |
| 4 | Number of windows: 9 | Cost: £26 | |
| 5 | Number of windows: 10 | Cost: £27.50 | |
| 6 | Number of windows: 11 | Cost: £28.50 | |
| 7 | Number of windows: 13 | Cost: £30.50 | |
| 8 | Number of windows: 15 | Cost: £32.50 |
Adapt your code to include a 10% discount in the quoted price.
