0
我努力讓自己在Python中的石頭,剪子,布的計劃,但每當我跑我的程序它給了我一個錯誤說這個,當我想重新運行我的某個函數時,爲什麼會出現錯誤?
File "C:/Users/Home/PycharmProjects/untitled/hi.py", line 59, in <module>
play_again = input("Do you want to play again? y/n")
File "<string>", line 1, in <module>
NameError: name 'y' is not defined
我知道你可能會想我的代碼,所以這裏是,
from random import *
import os, pygame
moves = ['Rock','Paper','Scissors']
def game():
move=choice(moves)
player = input("pick a move, 1. Rock, 2. Paper, 3. Scissors")
if (player == 1 and move == 1):
print(move, player)
print("It is a tie!")
if (player == 1 and move == 2):
print (move, player)
print("The computer wins!")
if (player == 1 and move == 3):
print (move, player)
print("You win!")
if (player == 2 and move == 1):
print (move, player)
print("You win!")
if (player == 2 and move == 2):
print (move, player)
print("It's a tie!")
if (player == 2 and move == 3):
print (move, player)
print("The computer wins!")
if (player == 3 and move == 2):
print (move, player)
print("You win!")
if (player == 3 and move == 3):
print (move, player)
print("It's a tie!")
if (player == 3 and move == 1):
print (move, player)
print("The computer wins!")
game()
play_again = input("Do you want to play again? y/n")
if(play_again == "y"):
game()
請問你能幫我嗎?謝謝
您正在運行python 2並且'input'沒有按照您的想法進行操作。在python 2你應該使用'raw_input' – jgritty
我確信這是我運行的代碼 – zane
運行* ....... – zane