0

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...)

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Gribouillis
0

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
else: 
    print exp
0

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:
        break
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.