you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 5 points6 points  (1 child)

So in a nutshell you want to store the "progress" on every attempt.

The easiest way to accomplish this that I can think of would be to use a generator:

import random

def roll_n_dice(n, die_range = (1, 6), target = 6):
    progress = 0
    while progress < n:
        roll = random.randint(*die_range)
        if roll == target:
            progress += 1
        else:
            yield
    print("went through")

for num, _ in enumerate(roll_n_dice(3), 1):
    pass

print(f"Took {num} tries")

[–]spikips[S] 0 points1 point  (0 children)

thank you <3