石头剪刀布转动倒计时和计分器

问题描述 投票:0回答:1

我已经用 Python 成功创建了剪刀石头布,但在实际让玩家玩七局两胜的游戏时遇到了麻烦。

我希望游戏运行 7 次,计算分数(即计算机是否获胜、玩家获胜或游戏平局),然后在最后将这些分数告诉玩家。下面的代码只是游戏本身,没有任何

while
循环来指示回合,因为我无法让回合系统工作。

每当我让它正确工作时,它总是会选择它前 7 次选择的任何内容,而不是随机选择(石头、布或剪刀)。

import random

choices = ["Rock", "Scissors", "Paper"]
choice = random.choice(choices)

#     should i put a while loop in game() or outside? neither make the choice random, it's always whatever the computer chose first


def game():
    prompt = input("Rock, paper or scissors?: ").title()
    match prompt:
        case "Rock":
            if choice == "Paper":
                print("Paper, I win!")
            if choice == "Scissors":
                print("Scissors, you win!")
        case "Paper":
            if choice == "Scissors":
                print("Scissors, I win!")
            if choice == "Rock":
                print("Rock, you win!")
        case "Scissors":
            if choice == "Rock":
                print("Rock, I win!")
            if choice == "Paper":
                print("Paper, you win!")
    if choice == prompt:
        print(f"{choice}, Tie!")


game()
python loops random numbers
1个回答
0
投票

我建议使用循环并将每个结果存储在列表中,最后计数 0 或 1 为计算机获胜分配 0,否则如果 0 计数大于计算机获胜则分配 1,否则为人类获胜。如果 0 和 1 都相等,则平局

© www.soinside.com 2019 - 2024. All rights reserved.