繁体   English   中英

我试图在python中做一个简单的测验,但一切都返回False?

[英]I am trying to make a simple quiz in python but everything returns False?

我输入的每个答案都返回False; 甚至A。有人可以帮我吗。

def space():
print' '
print 'Welcome to the quiz'
space()
print 'Chose the correct answer'
space()
print 'Who am I? '
space()
print "A. Zachary  "
print "B. Max"
print "C. Nick"
print "D. All of the above"
print 'type in the correct answer'
answer = raw_input()
if answer == 'a':
    print True
else:
    print False

更改if answer == 'a':改为if answer == 'a' or answer == 'A':或者,按照Paul Rooney的建议 ,可以使用if answer.lower() == 'a':

另外,在def space(): ,应该缩进print ' '

def space():
    print ' '
print 'Welcome to the quiz!'
space()
print 'Chose the correct answer.'
space()
print 'Who am I? '
space()
print "A. Zachary  "
print "B. Max"
print "C. Nick"
print "D. All of the above"
print 'Type in the correct answer.'
answer = raw_input()
if answer == 'a' or answer == 'A':
    print True
else:
    print False

键入Aa产量True

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM