예외

2016-10-16 2 views
0

나는 ValueError를예외

while True: 
    try: 
     input1,input2= input("Enter the Lat and Long of the source point separated by a comma eg 50,30").split(',') 
     break 
    except ValueError: 
     print ("please Use a Comma") 
     input1,input2 = input("Enter the Lat and Long of the source point separated by a comma eg 50,30").split(',') 
을 사용자가 올바른 입력을 제공하지만 사용자가 잘못된 입력을 제공하는 경우 첫 번째 루프 후 다시 프로그램이 충돌하고 나에게 줄 것이다 때까지 루프에이 코드를 얻으려고

답변

0

트릭은 예외가 발생했을 때 계속 문을 사용하는 것입니다. 그러면 루프가 다시 시작되고 시도로 보호되는 영역으로 들어갑니다. 문 때문에 다른 예외가 발생해도 프로그램이 중단되지 않습니다.

while True: 
    try: 
     value1, value2 = input("Enter the Lat and Long of the source point separated by a comma eg 50,30: ").split(',') 
     break 
    except ValueError: 
     print("Please Use a Comma") 
     continue