import tkinter
import random
def rollDice():
x=random.randint(1,6)
total=0
if x == 1:
total+=1
....
print(total)
我想補充每個號碼我在.rollDice
卷和存儲到total
總數,以及最大爲50。我怎樣才能做到這一點?如何我搖骰子和存儲使用Python3.4
import tkinter
import random
def rollDice():
x=random.randint(1,6)
total=0
if x == 1:
total+=1
....
print(total)
我想補充每個號碼我在.rollDice
卷和存儲到total
總數,以及最大爲50。我怎樣才能做到這一點?如何我搖骰子和存儲使用Python3.4
正如@PaulRooney所說,我不知道tkinter
與此有什麼關係。據我瞭解,你要滾骰子直到你total
達到或超過50 ..所以這裏是我對這個:
from random import randint
def rollDice():
return randint(1,6)
total = 0
while total < 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
你是什麼意思_maximum是50_?在「總數」變爲50或更多或擲骰子50次之前?你也不需要檢查'x'的值。只需將它添加到總數中,如下所示:'total + = x' –
這聽起來像您要求我們做功課。 –
不知道這與tkinter有什麼關係。你已經有了'+ ='運算符,所以進入while循環(總數小於或等於50 I.e' <='),並且每次添加骰子滾動的結果。 –