2017-11-11 12 views
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?') 

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

你'print'聲明應放在*後* while循環(修復它縮進的方式) – alfasin

+1

刪除而。全部刪除:全部縮進基線並輸出。其編碼atm的方式會在第一個正確答案中設置爲1,打破這個尷尬局面並在不打印任何東西的情況下結束它。 –

+0

歡迎來到SO。請花時間閱讀[問]。 – wwii

回答

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 ") 
相關問題