石头剪刀Python程序

石头剪刀Python程序,python,wing-ide,Python,Wing Ide,我正试图用Python编写一个石头剪刀程序,但我一直遇到这个错误,我不知道如何修复它 File "C:\Python33\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 140, in <module> File "C:\Python33\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 34, in main builtins.TypeError: 'tupl

我正试图用Python编写一个石头剪刀程序,但我一直遇到这个错误,我不知道如何修复它

 File "C:\Python33\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 140, in <module>
  File "C:\Python33\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 34, in main
builtins.TypeError: 'tuple' object is not callable
错误1:

修正第27行:结果=确定winnercomputer选项,玩家选项

错误2:

if player_choice == ROCK_CHOICE and computer_choice == ROCK_CHOICE:
NameError: global name 'ROCK_CHOICE' is not defined
移动:

3号线外干道

错误3:

File "main.py", line 41, in main
    play_again = input('Play again? Enter y for yes')
  File "<string>", line 1, in <module>
NameError: name 'y' is not defined
注意。输入“\n按ENTER继续…”也需要是原始输入


NNBB。如果您计划使用显示结果;那里也有错误。

您不认为,这样代码会更短:

from random import randint

class RPS:
    def __init__(self, pCh):
        self.playChoice = pCh
        self.compChoice = ""
        self.choice = randint(0, 3)
        self.winner = ""
        self.uCompChoice = ""
        self.uPlayChoice = ""
        if self.choice == 0:
            self.compChoice = "R"
        elif self.choice == 1:
            self.compChoice = "P"
        else:
            self.compChoice = "S"

    if self.compChoice == "R":
        self.uCompChoice = "Rock"
    if self.compChoice == "P":
        self.uCompChoice = "Paper"
    if self.compChoice == "S":
        self.uCompChoice = "Scissors"
    if self.playChoice == "P" or self.playChoice == "p" or self.playChoice == "Paper" or self.playChoice == "paper" or self.playChoice == "PAPER" or self.playChoice == "2":
        self.uPlayChoice = "Paper"
    if self.playChoice == "S" or self.playChoice == "s" or self.playChoice == "Scissors" or self.playChoice == "scissors" or self.playChoice == "SCISSORS" or self.playChoice == "3":
        self.uPlayChoice = "Scissors"
    if self.playChoice == "R" or self.playChoice == "r"  or self.playChoice == "Rock"  or self.playChoice == "rock"  or self.playChoice == "ROCK" or self.playChoice == "1":
        self.uPlayChoice = "Rock"

def determineWinner(self):
    if self.uCompChoice == self.uPlayChoice:
        return "Draw Game!"
    elif self.uCompChoice == "Rock":
        if self.uPlayChoice == "Paper":
            return "You won because Paper covers Rock!!"
        else:
            return "Computer wins because Rock breaks Scissors."
    elif self.uCompChoice == "Paper":
        if self.uPlayChoice == "Scissors":
            return "You won because Rock cuts Paper!!"
        else:
            return "Computer wins because Paper covers Rock."
    else:
        if self.uPlayChoice == "Rock":
            return "You won because Rock breaks Scissors!!"
        else:
            return "Computer wins because Scissors cuts Paper."



def __str__(self):
    return "Your weapon: " + self.uPlayChoice + "\n" + "Computer's weapon " + self.uCompChoice + "\n" + \
           self.determineWinner()

def main():
    print("Welcome to RockPaperScissors.")
    print("Pick your weapon: ")
    print("1. Rock")
    print("2. Paper")
    print("3. Scissors")
    print("Note: If you don't pick a valid weapon the computer will pick a random weapon for you")
    # input from user (weapon)
    weapon = input("")
    # Creating a new object
    attack = RPS(weapon)
    # printing the result
    print(attack.__str__())
    # Asking the user if he wants to play again
    playagain = input("Would you like to play again: \n")
    if playagain == "Yes" or playagain == "yes" or playagain == "YES" or playagain == "y" or playagain == "Y":
        main()
    else:
        print("Thank you for playing.")


main()
print("R for rock")
print("P for paper")
print("S for scissors")
choices = ["rock", "paper", "scissor"]


while True:
    choice = random.choice(choices)
    player_choice = input("choose> ")
    if player_choice.lower() == "r":
        if choice == "rock":
            print("i picked rock too!")
        elif choice == 'paper':
            print("YOU LOST! i picked paper")
        else:
            print("fine, you win")
    elif player_choice.lower() == "p":
        if choice == "rock":
            print("You win.... Whatever!")
        elif choice == 'paper':
            print("haha same decisions")
        else:
            print("I won! You should be ashamed of losing against a bot")
    elif player_choice.lower() == "s":
        if choice == "rock":
            print("I won! Humanity will soon be controlled by bots")
        elif choice == 'paper':
            print("Alright, you win")
        else:
            print("Draw")
    else:
        print("YOU WANNA PLAY GAMES WITH ME!??!?!?")

确定胜利者=计算机选择,玩家选择应该是结果=确定胜利者计算机选择,玩家选择,这个程序充满了错误。请在发布之前先测试它。是的,或者获得一个IDE,例如Pycharm社区版也将有助于指出明显的错误。或者
play_again = raw_input('Play again? Enter y for yes')
from random import randint

class RPS:
    def __init__(self, pCh):
        self.playChoice = pCh
        self.compChoice = ""
        self.choice = randint(0, 3)
        self.winner = ""
        self.uCompChoice = ""
        self.uPlayChoice = ""
        if self.choice == 0:
            self.compChoice = "R"
        elif self.choice == 1:
            self.compChoice = "P"
        else:
            self.compChoice = "S"

    if self.compChoice == "R":
        self.uCompChoice = "Rock"
    if self.compChoice == "P":
        self.uCompChoice = "Paper"
    if self.compChoice == "S":
        self.uCompChoice = "Scissors"
    if self.playChoice == "P" or self.playChoice == "p" or self.playChoice == "Paper" or self.playChoice == "paper" or self.playChoice == "PAPER" or self.playChoice == "2":
        self.uPlayChoice = "Paper"
    if self.playChoice == "S" or self.playChoice == "s" or self.playChoice == "Scissors" or self.playChoice == "scissors" or self.playChoice == "SCISSORS" or self.playChoice == "3":
        self.uPlayChoice = "Scissors"
    if self.playChoice == "R" or self.playChoice == "r"  or self.playChoice == "Rock"  or self.playChoice == "rock"  or self.playChoice == "ROCK" or self.playChoice == "1":
        self.uPlayChoice = "Rock"

def determineWinner(self):
    if self.uCompChoice == self.uPlayChoice:
        return "Draw Game!"
    elif self.uCompChoice == "Rock":
        if self.uPlayChoice == "Paper":
            return "You won because Paper covers Rock!!"
        else:
            return "Computer wins because Rock breaks Scissors."
    elif self.uCompChoice == "Paper":
        if self.uPlayChoice == "Scissors":
            return "You won because Rock cuts Paper!!"
        else:
            return "Computer wins because Paper covers Rock."
    else:
        if self.uPlayChoice == "Rock":
            return "You won because Rock breaks Scissors!!"
        else:
            return "Computer wins because Scissors cuts Paper."



def __str__(self):
    return "Your weapon: " + self.uPlayChoice + "\n" + "Computer's weapon " + self.uCompChoice + "\n" + \
           self.determineWinner()

def main():
    print("Welcome to RockPaperScissors.")
    print("Pick your weapon: ")
    print("1. Rock")
    print("2. Paper")
    print("3. Scissors")
    print("Note: If you don't pick a valid weapon the computer will pick a random weapon for you")
    # input from user (weapon)
    weapon = input("")
    # Creating a new object
    attack = RPS(weapon)
    # printing the result
    print(attack.__str__())
    # Asking the user if he wants to play again
    playagain = input("Would you like to play again: \n")
    if playagain == "Yes" or playagain == "yes" or playagain == "YES" or playagain == "y" or playagain == "Y":
        main()
    else:
        print("Thank you for playing.")


main()
print("R for rock")
print("P for paper")
print("S for scissors")
choices = ["rock", "paper", "scissor"]


while True:
    choice = random.choice(choices)
    player_choice = input("choose> ")
    if player_choice.lower() == "r":
        if choice == "rock":
            print("i picked rock too!")
        elif choice == 'paper':
            print("YOU LOST! i picked paper")
        else:
            print("fine, you win")
    elif player_choice.lower() == "p":
        if choice == "rock":
            print("You win.... Whatever!")
        elif choice == 'paper':
            print("haha same decisions")
        else:
            print("I won! You should be ashamed of losing against a bot")
    elif player_choice.lower() == "s":
        if choice == "rock":
            print("I won! Humanity will soon be controlled by bots")
        elif choice == 'paper':
            print("Alright, you win")
        else:
            print("Draw")
    else:
        print("YOU WANNA PLAY GAMES WITH ME!??!?!?")