当我想重新运行我的某个功能时,为什么会出现错误?

时间:2016-05-10 23:35:21

标签: python

我正在尝试在Python上制作摇滚,纸张,剪刀程序但是每当我运行我的程序时,它都会给我一个错误说明,

| 0.9 || 1.0 || 0.2 || 0.4 || 0.7 || 0.6 || 0.8 || 0.4 || 0.4 || 1.0 || 0.3 || 0.4 || 0.1 || 0.4 || 0.7 |
| 0.4 || 0.5 || 0.9 || 0.4 || 0.9 || 1.0 || 0.7 || 0.1 || 0.2 || 0.3 || 0.4 || 0.5 || 0.6 || 0.1 || 0.1 |
| 0.6 || 0.1 || 0.7 || 0.3 || 0.3 || 0.8 || 0.9 || 0.1 || 0.7 || 0.8 || 0.3 || 0.5 || 0.1 || 0.4 || 0.6 |
| 0.6 || 0.8 || 0.7 || 0.0 || 0.3 || 0.2 || 0.8 || 0.6 || 0.6 || 0.6 || 0.2 || 0.9 || 0.9 || 0.2 || 0.3 |
| 0.0 || 0.2 || 0.3 || 0.3 || 0.4 || 0.2 || 0.7 || 0.8 || 0.0 || 0.9 || 0.5 || 0.4 || 0.3 || 0.7 || 0.6 |
| 0.5 || 0.6 || 0.7 || 0.6 || 0.7 || 0.6 || 0.8 || 0.6 || 0.8 || 0.9 || 0.8 || 0.6 || 0.1 || 0.7 || 0.2 |
| 0.9 || 1.0 || 0.9 || 0.4 || 0.7 || 0.1 || 0.2 || 0.8 || 0.0 || 0.4 || 0.9 || 0.1 || 0.7 || 0.1 || 0.8 |
| 0.8 || 0.6 || 0.9 || 0.9 || 0.1 || 0.5 || 0.2 || 0.3 || 0.5 || 0.7 || 0.2 || 0.6 || 0.5 || 0.4 || 0.6 |
| 0.6 || 0.6 || 0.1 || 0.9 || 0.0 || 0.5 || 0.5 || 0.9 || 0.9 || 0.5 || 0.3 || 0.8 || 0.7 || 0.2 || 0.8 |
| 0.5 || 0.2 || 0.4 || 1.0 || 0.1 || 0.2 || 0.7 || 0.2 || 0.6 || 0.6 || 0.7 || 0.7 || 0.5 || 0.7 || 0.5 |
| 0.5 || 0.7 || 0.4 || 0.4 || 0.8 || 0.2 || 1.0 || 0.8 || 0.1 || 0.3 || 0.3 || 0.7 || 1.0 || 0.4 || 0.9 |
| 0.7 || 0.5 || 0.1 || 0.6 || 0.2 || 0.0 || 0.2 || 0.5 || 0.3 || 0.4 || 0.9 || 0.5 || 0.5 || 0.2 || 0.3 |
| 0.9 || 0.0 || 0.2 || 0.4 || 1.0 || 0.5 || 0.4 || 0.3 || 0.5 || 0.6 || 0.6 || 0.4 || 0.4 || 0.7 || 0.8 |
| 0.5 || 0.7 || 0.7 || 0.7 || 0.9 || 0.2 || 0.6 || 0.8 || 0.5 || 0.5 || 0.3 || 0.2 || 0.2 || 1.0 || 0.8 |
| 0.8 || 0.4 || 0.6 || 0.7 || 0.5 || 0.3 || 0.5 || 0.6 || 0.5 || 0.3 || 0.3 || 0.2 || 0.6 || 0.0 || 0.6 |

我知道你可能想要我的代码,所以在这里,

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
你能帮帮我吗?谢谢

1 个答案:

答案 0 :(得分:2)

您正在运行Python2。 Python2中的input尝试将用户的条目解释为代码。 y并不意味着任何事情(除非您已声明变量NameError,否则y,但不管它是"y" 1 })。 23raw_input 执行意味着某些事情(在您的代码中使用)

你应该总是在Py2中使用if,它将用户的条目解释为字符串。您还必须将之前的if player == "1" and moves == 1语句调整为字符串(viewDidLoad等)