당신이 그것을 설치를내는 방법은 다음과 더 많은 코드없이 잘못하고있는 일을 보여 어렵지만,
def WantToQuit():
Quit = raw_input("Please enter y if you are sure you want to quit, if not press n to return ")
if Quit == 'y':
return true
elif Quit == 'n':
return false
else:
# TODO: Handle this !
pass
while(True):
DisplayMenu()
# Some logic to get input and handle it
# For example, something like
selection = raw_input("Please make a selection: ").lower()
if(selection == "1"):
doSomething()
elif(selection == "2"):
doSomethingElse()
elif(selection == "q"):
if(WantToQuit()): break
else:
# TODO: Handle this !
pass
이
def WantToQuit():
Quit = raw_input("Please enter y if you are sure you want to quit, if not press n to return ")
if Quit == 'y':
sys.exit(0)
elif Quit == 'n':
return # Do nothing really
else:
# TODO: Handle this !
pass
while(True):
DisplayMenu()
# Some logic to get input and handle it
# For example, something like
selection = raw_input("Please make a selection: ").lower()
if(selection == "1"):
doSomething()
elif(selection == "2"):
doSomethingElse()
elif(selection == "q"):
WantToQuit()
else:
# TODO: Handle this !
pass
첫 번째 예는 WantToQuit
재미 있습니다
양자 택일로, 당신은 뭔가를 할 수 사용자 이 실제로을 종료할지 여부를 부울 값으로 반환합니다. 그렇다면 무한 루프가 끊어지고 프로그램이 자연적으로 종료됩니다.
두 번째 예제는 WantToQuit
함수 내에서 종료를 처리하고 sys.exit()
을 호출하면 즉시 종료됩니다.
두 가지가 실제로 사용되지만 첫 번째 방법이 좋습니다.
다음
quit
기능은라는 상자가 나타납니다 자체적으로 재귀 적으로? –당신은 정말로 코드를 들여 줘야합니다. 그래서 return 문이나 두번째 raw_input이 어디에 속해 있는지 알 수 있습니다. –
그냥 두번 호출했음을 깨달았습니다. 마지막에 어떤 함수가 반환되어야합니까 ?? – user1655562