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

时间:2016-12-14 02:27:06

标签: python python-2.7

我输入的每个答案都返回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

1 个答案:

答案 0 :(得分:1)

if answer == 'a':更改为if answer == 'a' or answer == 'A':或,根据the suggestion of 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