Python Projects & Skills / Games
Lesson 7 of 28
Rock, paper, scissors
Store what beats what in a dictionary, so the game logic is one line instead of nine ifs.
Key points
- Dictionaries simplify rules
- random.choice picks the computer's move
- Track a best-of-five score
beats = {"rock": "scissors", "paper": "rock", "scissors": "paper"}
if beats[me] == cpu:
print("You win")Quiz · +10 XP
In the dictionary above, what does rock beat?
Log in to save progress and earn XP.