這應該是一個測試程序,我可以在其上練習python。我定義了main並構建了代碼。當答案是正確的時候,我按下'Y',它應該跳到下一個代碼塊的下一個函數,在這個函數結束之後。錯誤是這樣的:調用另一個函數錯誤
NameError: name 'logic_ques' is not defined.
如何在按'y'並且沒有出現錯誤後啓動下一個功能?問題是順序嗎?
def main():
pts = 0
numberStr = input("Please enter the sum of 251 and 516: \n ")
num = int(numberStr)
print ('You have entered: ', num)
if (num == 767):
pts += 1
print ('The answer is correct!')
print ('You currently have ', pts, 'point(s).')
continue1 = input('Press any key to see the next question.')
logic_ques()
else:
print ('The answer is not correct.')
restart = input('The answer is wrong, type Y if you want to restart, and N if you want to exit. \n')
if (restart == 'y'):
main()
else:
exit()
main()
def logic_ques():
logicStr = input("Which animal sleeps on legs, not lying down?")
print ('You have entered the following animal:', logicStr)
if (logicStr == 'horse'):
pts += 1
print ('The asnwer is correct!')
print ('You currently have ', pts, 'points.')
continue1 = input('Press any ket to see the next question.\n')
else:
print ('The asnwer is not correct!')
restart1 = input('The answer is wrong, type Y if you want to restart, and N if you want to exit. \n')
if (restart1 == 'y'):
logic_ques()
else:
exit()
logic_ques()
你叫'main'的定義之前移動logic_ques()的定義**之前調用點上方**到達點在你定義'logic_ques'的腳本中。是的,問題在於訂單。 – jonrsharpe