python问题似乎无法检查某些值

2024-09-21 01:13:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚开始我的第一门语言:python。所以我开始练习,试着写一个石头,布,剪刀的游戏。我知道我不是最好的,但似乎不能让比赛结束时,美国计数和comp\u计数达到最大值

import random
us_count = 0
comp_count = 0
gamelim = None
def GameConfig(gamelim,us_count,comp_count):
    gamelim = input("How long do you want the game to be: \n")
    Game(gamelim,us_count,comp_count)
def GameLoop(gamelim,us_count,comp_count):
    if us_count > comp_count and us_count + comp_count == gamelim:
        print("You have the best ",us_count," out of ",gamelim)
        GameEnd()
    elif us_count < comp_count and us_count + comp_count == gamelim:
        print("Computer has bested ",comp_count," out of ",gamelim)
        GameEnd()
    elif us_count == comp_count and us_count + comp_count == gamelim:
        print("Game tied.")
        GameEnd()
    else:
        Game(gamelim,us_count,comp_count)
def GameEnd():
    gamecont = print("Game has ended do you want to play again?")
    end
def Game(gamelim,us_count,comp_count):
    us_choice = str(input("Please select rock, paper or scissors: \n"))
    choices = ["rock","paper","scissors"]
    comp_choice = random.choice(choices)
    if us_choice == comp_choice:
        print("Computer choses " + comp_choice + "\nIt'a tie.")
    elif us_choice == "rock" and comp_choice == "scissors":
        print("Computer choses " + comp_choice + "\nYou won.")
        us_count = us_count + 1
    elif us_choice == "rock" and comp_choice == "paper":
        print("Computer choses " + comp_choice + "\nYou lost.")
        comp_count = comp_count + 1 
    elif us_choice == "paper" and comp_choice == "rock":
        print("Computer choses " + comp_choice + "\nYou won.")
        us_coun = us_count + 1
    elif us_choice == "paper" and comp_choice == "scissors":
        print("Computer choses " + comp_choice + "\nYou lost.")
        comp_count = comp_count + 1
    elif us_choice == "scissors" and comp_choice == "paper":
        print("Computer choses " + comp_choice + "\nYou won.")
       us_count = us_count + 1 
    elif us_choice == "scissors" and comp_choice == "rock":
        print("Computer choses " + comp_choice + "\nYou lost.")
        comp_count = comp_count + 1
    else:
        print("Please enter a corret value")
    GameLoop(gamelim,us_count,comp_count)
GameConfig(gamelim,us_count,comp_count)

Tags: andgamecountcomputerpaperusprintscissors

热门问题