这应该是一个测试程序,我可以在其上练习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