簡體   English   中英

紙牌游戲,循環返回無

[英]Cardgame, loop returns None

我似乎無法讓這個工作。 我有一個簡單的更高或更低紙牌游戲的循環,我想做的是返回卡片或卡片的任何值,以及積分,以便我可以腌制它們進行存儲並玩這個游戲一遍又一遍。 但是,我只能在循環的第一次迭代中返回卡片和積分。 每當在 function 中再次調用 gameloop function 時,最后一行的打印 function 將打印 None。

def gameloop(rand_card, rand_type, point):
    point = point
    card = rand_card, rand_type
    print("The card is:")
    print_card(card[0], card[1])
    print("Do you bet on a higher or lower value to be drawn? (H/L)")
    ans = input().lower()

    if ans == "q":
        return card, point

    new_card = random_card(), random_type()
    print("The new card is:")
    print_card(new_card[0], new_card[1])


    if ans == "h":
        if new_card[0] > card[0]:
            print("Congratulations, the new card was higher. You have been awarded one point.")
            point += 1
        elif new_card[0] < card[0]:
            print("Sorry, the new card was lower. One point has been deducted.")
            point -= 1
        else:
            print("It's a tie! No points deducted.")

    elif ans == "l":
        if new_card[0] < card[0]:
            print("Congratulations, the new card was lower. You have been awarded one point.")
            point += 1
        elif new_card[0] > card[0]:
            print("Sorry, the new card was higher. One point has been deducted.")
            point -= 1
        else:
            print("It's a tie! No points deducted.")

    print("You have a total of {} points.".format(point))
    gameloop(new_card[0], new_card[1], point)

data = gameloop(random_card(), random_type(), 0)

print(data)

return gameloop(new_card[0], new_card[1], point)而不是gameloop(new_card[0], new_card[1], point) ,解決了問題,謝謝quamrana。

暫無
暫無

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

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