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

时间:2016-12-12 15:54:18

标签: python python-3.x

我刚刚开始使用我的第一语言:python。所以我开始练习并试着写一个摇滚,纸,剪刀游戏。我知道我并不是最好的,但是当us_count和comp_count达到最大值时,似乎无法让游戏结束

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)

0 个答案:

没有答案