How do I roll a dice and store the total number using Python3.4
<pre><code>import tkinter
import random

def rollDice():
   x=random.randint(1,6)
   total=0
   if x == 1:
   total+=1
   ....
print(total)
</code></pre>

<p>I would like to add each number I roll in <code>.rollDice</code> and store into <code>total</code> , and maximum is 50. How can I do that?</p>

<p>As @PaulRooney says, i am not sure what <code>tkinter</code> has to do with this. From what i understand, you want to roll a dice until your <code>total</code> reaches or exceeds 50.. So here is my take on this:</p>

<pre><code>from random import randint

def rollDice():
    return randint(1,6)

total = 0
while total &lt; 50:
    new_roll = rollDice()
    total += new_roll
    print('You rolled a {}. The new total is {}'.format(new_roll, total))
# You rolled a 3. The new total is 3
# You rolled a 3. The new total is 6
# You rolled a 4. The new total is 10
# You rolled a 6. The new total is 16
# You rolled a 2. The new total is 18
# You rolled a 1. The new total is 19
# You rolled a 5. The new total is 24
# You rolled a 5. The new total is 29
# You rolled a 4. The new total is 33
# You rolled a 5. The new total is 38
# You rolled a 2. The new total is 40
# You rolled a 3. The new total is 43
# You rolled a 4. The new total is 47
# You rolled a 6. The new total is 53
</code></pre>

python tkinter