Escape Room 3.15 - Hacks & Extensions
Extended Python challenges and hacks for CSP 3.15 Escape Room - Random Values
🚀 Escape Room Python Hacks
- Simulate rolling two dice and show all possible sums of their outcomes.
# 🎲 Die faces: 1, 2, 3, 4, 5, 6
# TODO: Write code to calculate and display all possible sums
# Hint: You may need two nested loops
for die1 in range(1, 7):
for die2 in range(1, 7):
total = die1 + die2
print(f"{die1} + {die2} = {total}")
1 + 1 = 2
1 + 2 = 3
1 + 3 = 4
1 + 4 = 5
1 + 5 = 6
1 + 6 = 7
2 + 1 = 3
2 + 2 = 4
2 + 3 = 5
2 + 4 = 6
2 + 5 = 7
2 + 6 = 8
3 + 1 = 4
3 + 2 = 5
3 + 3 = 6
3 + 4 = 7
3 + 5 = 8
3 + 6 = 9
4 + 1 = 5
4 + 2 = 6
4 + 3 = 7
4 + 4 = 8
4 + 5 = 9
4 + 6 = 10
5 + 1 = 6
5 + 2 = 7
5 + 3 = 8
5 + 4 = 9
5 + 5 = 10
5 + 6 = 11
6 + 1 = 7
6 + 2 = 8
6 + 3 = 9
6 + 4 = 10
6 + 5 = 11
6 + 6 = 12
- Create a fortune teller program. The response “Try Again” should appear 40% of the time, while the other possible responses are “Yes”, “No”, and “Maybe”.
import random
# 🔮 Fortune Teller
# TODO: Generate a random number between 1 and 100
num = random.randint(1, 100)
if num <= 25:
print("Try Again")
elif num <= 50:
print("Yes")
elif num <= 75:
print("No")
else:
print("Maybe")
Try Again
- Create a program that randomly selects a meal from a menu list. For example: “Pizza”, “Burger”, “Salad”, “Pasta”, “Sushi”.
import random
meals = ["chipotle", "rice", "pasta", "steak", "cava"]
choice = random.choice(meals)
print("You should eat:", choice)
You should eat: pasta
- Practice using random.choice() and random.shuffle().
-
Use random.choice() to select one random card from a deck.
-
Use random.shuffle() to shuffle the entire deck.
import random
# 🃏 Deck of cards (simplified as numbers 1–10 for this example)
deck = [1,2,3,4,5,6,7,8,9,10]
# TODO: Use random.choice() to pick one card
# TODO: Use random.shuffle() to shuffle the deck and print it
card = random.choice(deck)
print("You picked:", card)
random.shuffle(deck)
print("Shuffled deck:", deck)
You picked: 2
Shuffled deck: [2, 4, 7, 6, 8, 3, 9, 10, 5, 1]