我正在尝试编写一个骰子游戏,其中每个掷骰将两个骰子总数加到一个变量上,并在掷骰函数的每次迭代中进行此操作,因此最后每个掷骰都有一个合计总数。 >
我已经尝试创建一个单独的函数来添加值,但是没有成功。
这是我的滚动功能:
def roll():
global die1
global die2
global dietotal
global diewholetotal
die1 = random.randint(1,6)
die2 = random.randint(1,6)
dietotal = (die1 + die2)
这是整个骰子游戏:
def dicegame():
truroll = input("Roll the dice? ")
if truroll == "Yes" or "yes" or "y" or "Y":
roll()
print("The rolls were:", die1, " and " ,die2, " and the total was: ", dietotal)
sprint("Rolling again...")
time.sleep(1)
# adding the roll to the total
print("The rolls were:", die1, " and " ,die2, " and the total was: ", dietotal)
sprint("Rolling again...")
# adding the roll to the total
time.sleep(1)
print("The rolls were:", die1, " and " ,die2, " and the total was: ", dietotal)
sprint("Rolling again...")
addnum(x)
time.sleep(1)
# adding the roll to the total
print("The rolls were:", die1, " and " ,die2, " and the total was: ", dietotal)
sprint("Rolling again...")
addnum(x)
time.sleep(1)
# adding the roll to the total
print("The rolls were:", die1, " and " ,die2, " and the total was: ", dietotal)
sprint("Rolling again...")
# adding the roll to the total
time.sleep(1)
print("The total for these rolls was: ", x)
print(#here would be the total for all the rolls added)
else:
print("Returning to games list...")
gamelist()
我并不是真的希望我的版本能正常工作,所以我用注释代替了它。希望你能帮忙