我叫Erkan,我在尝试制作骰子游戏时遇到问题。
我想做的核心事情是:
向玩家询问他想要多少个骰子。最小1(ofc),最大5。每个骰子只能掷一次。
然后,游戏应一次将每个骰子的结果随机化,并将其与到目前为止掷出的骰子的总和一起打印在屏幕上。
[如果任何骰子获得1,则不会将其添加到总和中(例如im来源的yatsy),但会抛出两个新骰子。当/发生时,应在屏幕上显示。只要任何骰子都为1,此过程就会重复。
扔掉所有骰子时,总和和扔出的骰子数会显示在屏幕上。然后,玩家应该可以选择再次玩还是退出游戏。
我是Python的初学者,很抱歉英语不好。是否可以就缺少的内容寻求帮助?
到目前为止,我的代码是:
from random import randint
amount_dices=int(input("How many dices do you want to use? Min 1, max 5"))
amount_dices_tossed = 1
result=[]
var1=0
while var1<amount_dices_tossed:
var1=var1+1
for i in range(amount_dices):
t=randint(1,6)
result.append(t)
print("Dices",i+1,":", t)
Sum = sum(t)
print(Sum)
Sum_dices = int(sum())
Sum_toss = str(sum(amount_dices_tossed))
print("The total amount: " +Sum_dicesg + " and you tossed: " + Sum_tossed + " dices")
choice = input("Do you want to play again? [yes/no]")
answer1 = "yes"
answer2 = "no"
if choice == yes:
else:
print("Thanks for playing!")
exit(0)
我不知道要重新开始时在“ if choice == yes”下应该怎么说。
要重复代码,请使用循环while True
和exit()
或break
完成循环并结束游戏。
while True:
# ... you code ...
choice = input("Do you want to play again? [yes/no]")
if choice != "yes":
print("Thanks for playing!")
#exit(0)
break