2016-03-29 57 views
-4

我想知道如何重置這個程序,我需要幫助。我一直在尋找答案,但我找不到可行的程序。有人可以幫幫我嗎?如何重複該程序?

print("Answer These MATH Questions") 
def program(): 
    math = int(input("What Is 8 x 4: ")) 
    if math == ("32"): 
     print("You Got The Question Correct") 
    else: 
     print("Sorry You Got The Question Wrong Try Again") 
     program() 
     return 
+2

爲什麼要將輸入轉換爲整數,如果您要將其與字符串進行比較? – zondo

+0

對不起,我編程新手 – ThatGuy

回答

0

使用while像例子。不要使用int輸入 - 也許它不會編號:

while 1: 
    math = input("What Is 8 x 4: ") 
    if not math.isdigit(): 
     print("It's not number") 

    elif math == "32": 
     print("You Got The Question Correct") 
     break 

    else: 
     print("Sorry You Got The Question Wrong Try Again") 
+0

您正在使用'elif'並仍然檢查同樣的情況嗎?爲什麼? – TigerhawkT3

+0

@ TigerhawkT3,第一個版本,只是,我忘了修復它。謝謝! – JRazor

0

變化if math == ("32"):if math == 32: