2013-09-01 3 views
-5

내 프로그램에서 사용자에게 프로그램을 다시 사용할지 묻습니다 (다시 시작). 파이썬 3.3에서 어떻게 할 수 있습니까? 어떻게 파이썬 3.3에서 루프를 만들 수 있습니까?

나는 그것은 당신이 파이썬에 존재하지 않는 do...while 같은 것을 찾고있는 것 같습니다이

loop=1 
while(loop==1): 



    #code 



loop-=1 
    done=0 
    while(done==0): 
     choice=input("Do you want to restart?(Y/N)") 
     choice1=choice.upper() 
     if(choice1=="Y"): 
      loop+=1 
      done=1 
      print("Restarting...") 
     elif(choice1=="N"): 
      done=1 
      print("The program will now END. Thank you for using the program.") 
+1

GIYF http://docs.python.org/ 3/reference/compound_stmts.html # (http://docs.python.org/3/reference/compound_stmts.html#while – Sinkingpoint

+0

) 무엇이 문제입니까? – slfan

답변

0

을 시도했다.

이 구조에 대한 교체 ("조건이 충족 될 때까지 반복 한 번 이상 실행")과 같이 구성 할 수있다 :

abort = False 
while not abort: 
    # do stuff 
    exit = input("Exit [Y/N]? ").lower() 
    if (exit == "y"): 
     abort = True 
3
while 1: 
    main() 
    if input('Continue? [y/n]') == 'n': # Ideally you would check they actually entered y or n 
     break 
관련 문제