簡體   English   中英

Python 中的游戲(骰子)

[英]Game in Python (Dice)

我的名字是 Erkan,我在嘗試構建一個骰子游戲時遇到了問題。

我想做的核心事情是:

詢問玩家他想要多少個骰子。 最小 1(ofc) 和最大 5。每個骰子只能擲一次。

然后,游戲應將每個骰子的結果隨機化,一次一個,並將其與迄今為止所擲骰子的總和一起打印在屏幕上。

如果任何骰子得到 1,則不會將其添加到總和中(例如 yatsy where im from),而是擲出兩個新骰子。 這應該在/如果發生時顯示在屏幕上。 只要任何骰子得到 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)

當我想重新開始時,我不知道在“如果選擇 == 是”下應該說什么。

要重復代碼,請使用 loop while Trueexit()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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM