测验代码,之后代码将输出用户得到的分数和分数。但由于某些原因,我无法打印此代码

时间:2017-11-11 15:26:27

标签: python

counter = 0

q1 = input('What is the capital of Germany?')
q2 = input('What is the name of Sideshow Bobs brother?')
q3 = input('In Family Guy how many voices does Seth MacFarlane do the characters to?')
q4 = input('Which famous pianist, wrote the movement called Moonlight Sonata?')
q5 = input('Which  famous rapper has recently revealed his withdrawal from music, due to a friendship problem?')

while True:

    if q1 == "Berlin":
        break
        counter = counter + 1
    else:

        if q2 == "Cecil": 
            break
            counter = counter + 1
        else:

            if q3 == "five": 
                break
                counter = counter + 1
            else:

                if q4 == "Beethoven":
                   break
                   counter = counter + 1
                else:

                    if q5 == "xxxtentacion":
                        break
                        counter = counter + 1
                    else:

                     print("You scored ", counter, " out of 5 ")

1 个答案:

答案 0 :(得分:0)

像这样:

counter = 0

q1 = input('What is the capital of Germany?')
q2 = input('What is the name of Sideshow Bobs brother?')
q3 = input('In Family Guy how many voices does Seth MacFarlane do the characters to?')
q4 = input('Which famous pianist, wrote the movement called Moonlight Sonata?')
q5 = input('Which  famous rapper has recently revealed his withdrawal from music, due to a friendship problem?')

if q1 == "Berlin":
    counter = counter + 1 

if q2 == "Cecil": 
    counter = counter + 1

if q3 == "five": 
    counter = counter + 1

if q4 == "Beethoven":
    counter = counter + 1

if q5 == "xxxtentacion":
    counter = counter + 1

print("You scored ", counter, " out of 5 ")