我正在嘗試朗姆酒模擬5個骰子的程序。我知道我錯過了一些簡單的東西,但我不能把它放在手指上。我試圖改變骰子整數,但它只打印輸出中的數字沒有被添加。我做了什麼???代碼在這裏,輸出如下。任何幫助都會很棒。提前致謝。在python中添加數字的問題
# This program will simulate dice rolls 5 different
# times and add the total of each roll.
import random
MIN = 1
MAX = 6
ROLLS = 5
def main():
print(random.randint(MIN, MAX))
print(random.randint(MIN, MAX))
for count in range(ROLLS):
if random.randint(MIN,MAX)== 2:
print('The total is two!')
elif random.randint(MIN,MAX)== 3:
print('The total is three!')
elif random.randint(MIN,MAX) == 4:
print('The total is four!')
elif random.randint(MIN,MAX) == 5:
print('The total is five!')
elif random.randint(MIN,MAX) == 6:
print('The total is six!')
elif random.randint(MIN,MAX) == 7:
print('The total is seven!')
elif random.randint(MIN,MAX) == 8:
print('The total is eight!')
elif random.randint(MIN,MAX) == 9:
print('The total is nine!')
elif random.randint(MIN,MAX) == 10:
print('The total is ten!')
elif random.randint(MIN,MAX) == 11:
print('The total is eleven!')
else:
print('The total is twelve!')
print('The dice will be rolled and the total shown')
print('each time enter is pressed up to five times!')
total = point(MIN, MAX)
print('The total is', total)
def point(MIN, MAX):
for count in range(MIN, MAX):
dicerolls = 0.0
total = 0.0
dice = input('')
total += dicerolls
return total
main()
2
2
The total is twelve!
The dice will be rolled and the total shown
each time enter is pressed up to five times!
The total is 0.0
The total is three!
The dice will be rolled and the total shown
each time enter is pressed up to five times!
The total is 0.0
The total is twelve!
The dice will be rolled and the total shown
each time enter is pressed up to five times!
The total is 0.0
The total is six!
The dice will be rolled and the total shown
each time enter is pressed up to five times!
The total is 0.0
The total is twelve!
The dice will be rolled and the total shown
each time enter is pressed up to five times!
The total is 0.0
每次你進行比較,你再次調用'randint',它會返回一個不同的隨機值。將結果放入變量中。 – Ryan
你的骰子滾動滾動,變成一個永不停止改變現值的球。 –