我不明白这里发生了什么,我没有太多编码,我做了其他编码项目,并解决了它们。我尝试过elif和else,但它们一直在说语法错误,尽管我可以看到其他人的代码与它们一起工作。
import random
def play():
user = input("What's your choice? rock, paper, scissorsn")
computer = random.choice("rock', 'paper', 'scissors")
if user == computer:
print('Its a tie')
def is_win(player, opponent):
if (player == 'rock' and opponent == 'scissors') or (player == 'scissors' and opponent == 'paper') or (player == 'rock' and opponent == 'paper'):
print('You won!')
def is_lose(player, opponent):
if (player == 'paper' and opponent == 'rock') or (player == 'scissors' and opponent == 'rock') or (player == 'paper' and opponent == 'scissors'):
print('you lost!')
print(play())
问题带有引号,没有对is_win
和is_lose
的调用。请与报价保持一致。
import random
def play():
user = input("What's your choice? rock, paper, scissorsn")
computer = random.choice(['rock', 'paper', 'scissors'])
if user == computer:
print('Its a tie')
elif (player == 'rock' and opponent == 'scissors') or (player == 'scissors' and opponent == 'paper') or (player == 'rock' and opponent == 'paper'):
print('You won!')
else:
print('you lost!')
play()
好的,所以在有人编辑了我的代码后,我仍然看到代码中有错误,所以我修复了它。其中一个错误是对手不能拥有岩石。这是完成的代码。
import random
def play():
player = input("What's your choice? rock, paper, scissorsn")
computer = random.choice(['rock', 'paper', 'scissors'])
if player == computer:
print('Its a tie')
elif (player == 'rock' and computer == 'scissors') or (player == 'scissors' and computer == 'paper') or (player == 'paper' and computer == 'rock'):
print('You won!')
else:
print('You lost!')
play(play())