我正在尝试使用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!")
答案 0 :(得分:0)
要做到这一点,请添加到文件的底部:
game = RPS()
game.play()
还有一些其他问题,但我会让你试着自己解决这些问题。