Unit 2 Task 13 - Solution

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

Solution - Task 13: Waiting for a lucky 7

← Back to task


One possible program:

import random

count = 0

while True:
    roll = random.randint(1, 10)
    count += 1
    print(roll)
    if roll == 7:
        break

print("It took", count, "attempts")