これを実行しようとすると、xが定義されていないというエラーが表示されます。私はPythonの初心者です。どんな助けもありがとう。また、このよりクリーンなコードを作成する方法は素晴らしいでしょう。Pythonロックペーパーはさみエラー
import random
choices = ["rock", 'paper', 'scissors']
def playainput():
playachoice = ("")
playerinput = input("Input rock, paper, or scissors: ")
if playerinput == ("rock"):
playachoice += ("you chose rock")
elif playerinput == ("paper"):
playachoice += ("you chose paper")
elif playerinput == ("scissors"):
playachoice += ("You chose scissors")
else:
print ("oops type again")
playainput()
print (playachoice)
def choose(x):
choice = random.choice(x)
print ("I chose %s" %choice)
x = playachoice
y = choose(choices)
if x == ("rock") and y == ("scissors"):
print ("you win")
if x == ("rock") and y == ("paper"):
print ("you lose!")
if x == ("rock") and y == ("rock"):
print ("tie")
if x == ("paper") and y == ("scissors"):
print ("I win!")
if x == ("paper") and y == ("paper"):
print ("tie!")
if x == ("paper") and y == ("rock"):
print ("you win!")
if x == ("scissors") and y == ("scissors"):
print ("tie!")
if x == ("scissors") and y == ("paper"):
print ("you win!")
if x == ("scissors") and y == ("rock"):
print ("you lose!")
を動作するはずだと思う逐語的に、完全なトレースバックを含めてくださいあなたの答えに直接。ありがとう。 –
サイドノート: 'str'リテラルを囲むこれらのランダムな括弧は無意味で、コードをもっと混乱させます(ビヘイビアには全く影響しません)。なぜあなたはそれらが必要だと思いますか? – ShadowRanger