Hi there, new programmer/python user here.

What I'm trying to do, is simulate the rules of a tabletop RPG (not nerdy in the slightest). This is using a 10-sided die. In the game when you roll a 10 the dice "explodes" and you roll it again and add the next roll to your total.

So if II roll a 10 I roll again and get a 3 and end with a 13. If I roll 2 10s in a row and an 8 I get a 28.

Well I used what little knowledge I have (3 days worth) and made my program. I run it a few times to see if it works. Well... I got a 20. "ok..." i say. So apparently it isn't looping. And I dont really understand whats going on =(. Any hints? (I'd post my code but I got frustrated and deleted it...)

8 Years
Discussion Span
Last Post by Gribouillis

I think i maybe figured it out.. is there a flaw to my logic? I made the random 9-10 for testing purposes

import random
num = random.randint(9,10)
exp = 0
if num < 10:
    print num
while num == 10:
    exp = exp + num
    num = random.randint(9,10)
    exp = exp + num
    print exp

Here is how you could do this

import random
result = 0
while True: # means forever
    roll = random.randint(1, 10)
    result += roll
    if roll != 10:
print result
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.