RPS代码不会运行但不会返回任何输出

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

我正在尝试使用Python 3.6.3在PyCharm中创建一个摇滚,纸张,剪刀游戏,但它在执行时不会返回任何输出,我在IDE中没有收到任何代码错误。

import random

class RPS:
    rock = 1        
    paper = 2
    scissors = 3

    def __init__(self, choice):
        self.choice = choice

    def play(self):
        print("Enter: \n1 for Rock, \n2 for Paper, \nor 3 for Scissors")
        choice = int(input("Enter in a number between 1 and 3: "))
        while (choice != 1 or choice != 2 or choice != 3):
            print("You have selected an invalid choice!")
            print("Enter: \n1 for Rock, \n2 for Paper, \nor 3 for Scissors")
            choice = int(input("Enter in a number between 1 and 3: "))
            print("You have selected", choice)

        computer = random.randint(1, 3)

        if computer == 1:
            print("The computer chose rock")

        if computer == 2:
            print("The computer chose paper")

        if computer == 3:
            print("The computer chose scissors")

        if choice > computer:
            print("You win!")

        elif choice < computer:
            print("You lose!")

        elif choice == computer:
            print("It is a tie!")

        play_again = input('Do you want to play again[yes/no]? ')
        if play_again.lower() == 'yes':
            self.play()

        if play_again.lower() == 'no':
            print("Thanks for playing! \nBYE!")
python-3.x loops
1个回答
0
投票

正如jasonharper所说,你不是在实践课程并运行它的游戏方法。

要做到这一点,添加到文件的底部:

game = RPS()
game.play()

还有一些其他问题,但我会让你试着自己解决这些问题。

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