下面在python2.7中执行的代码给出了一个NameError
。你知道吗
回溯是
answer1 = input("make a decision").Upper()
File "<string>", line 1, in <module>
NameError: name 'C' is not defined
完整的代码是。你知道吗
print("This is a quiz on Internet safety!")
print("Question 1")
print("What is a firewall?")
print("A-A killer hot wall!")
print("B-A protection from virus'")
print("C-A protection from bad websites!")
answer1 = input("make a decision").Upper()
if answer1 == "C":
print("Good!")
score = score+1
else:
print("You failed....")
quit
print("Question 2")
print("What is a virus?")
print("A-A killer disease! RUN!")
print("B-A harmful bit of mumbo-jumbo on the computer")
print("C-A harmful programme which encrypts the computer as invalid")
answer2 = input("make a decision").Upper()
if answer2 == "B":
print("Well Done!")
score = score+1
else:
print("You failed....")
quit
首先,函数是
upper
,而不是Upper
其次,程序在python3中执行得很精确。你知道吗
如果您使用的是python2,则需要使用返回字符串的
raw_input
,而不是input
。因此,这条线应该是输出将是完美的。你知道吗
而且
quit
应该是quit()
基于您的错误,您似乎正在使用python2。所以需要使用
raw_input
返回字符串。而是input
。你还需要用upper
来代替Upper
看起来score
和quit
在这里是多余的!你知道吗相关问题 更多 >
编程相关推荐