use*_*649 3 python input python-2.7
那么我在这里做错了什么?
answer = int(input("What is the name of Dr. Bunsen Honeydew's assistant?"))
if answer == ("Beaker"):
print("Correct!")
else:
print("Incorrect! It is Beaker.")
Run Code Online (Sandbox Code Playgroud)
但是,我只能得到
Traceback (most recent call last):
File "C:\Users\your pc\Desktop\JQuery\yay.py", line 2, in <module>
answer = int(input("What is the name of Dr. Bunsen Honeydew's assistant?"))
File "<string>", line 1, in <module>
NameError: name 'Beaker' is not defined
Run Code Online (Sandbox Code Playgroud)
您正在使用input
而不是raw_input
使用python 2,它将输入计算为python代码.
answer = raw_input("What is the name of Dr. Bunsen Honeydew's assistant?")
if answer == "Beaker":
print("Correct!")
Run Code Online (Sandbox Code Playgroud)
input()
相当于 eval(raw_input())
此外,您正在尝试将"Beaker"转换为整数,这没有多大意义.
您可以像这样替换脑中的输入,使用raw_input
:
answer = "Beaker"
if answer == "Beaker":
print("Correct!")
Run Code Online (Sandbox Code Playgroud)
并与input
:
answer = Beaker # raises NameError, there's no variable named Beaker
if answer == "Beaker":
print("Correct!")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
445 次 |
最近记录: |