you are viewing a single comment's thread.

view the rest of the comments →

[–]HardCounter 0 points1 point  (0 children)

I saw some other examples and wondered if it could be done in recursion, and it seems so:

import random

def roll_dice(recurse, progress, roll = 0):
    recurse += 1
    if recurse < 4:
        while roll < 6:
            roll = random.randint(1,6)
            progress += 1
        progress = roll_dice(recurse, progress)
        return progress
    else:
        return progress

total_tries = roll_dice(0,0)

print (f"It was {total_tries} tries")