Configurable Rounds
Understand slicing and how it lets players choose a shorter round from the bank
The quiz has ten questions — but it always runs all of them. There is no way to ask for a quick five-question warmup. In this lesson you will add a num parameter to run_quiz and a prompt in the while loop so players can choose how many questions to answer each round.
What you already know about lists
You have been working with QUESTIONS as a list since the beginning:
- len():
len(QUESTIONS)returns the count — you already use this inrun_quiz. - for loops: you already iterate over
QUESTIONSto ask each question. - Indexing:
QUESTIONS[0]returns the first item;QUESTIONS[-1]returns the last.
The new tool: slicing
A slice returns a portion of a list without changing the original:
numbers = [10, 20, 30, 40, 50]
print(numbers[:3]) # [10, 20, 30]
print(numbers[1:4]) # [20, 30, 40]numbers[:3] means "from the start, up to but not including index 3." You will use questions[:num] in run_quiz so the player can choose a shorter round from the bank.