App 1: Your First App, a Quiz Game / Build the quiz
Lesson 8 of 10
Shuffle and make it replayable
random.shuffle mixes the question order so every game feels new. Wrap the game in a function and ask if the player wants to go again.
Key points
- random.shuffle(list) mixes it in place
- Put the game in def play():
- A while loop asks to play again
import random
def play():
random.shuffle(questions)
...
while True:
play()
if input("Play again? (y/n) ").lower() != "y":
breakYour turn
Move your game into a play() function and add the play-again loop.
Quiz · +10 XP
What does random.shuffle(questions) do?
Log in to save progress and earn XP.