break outside loop
조회수 648회
import random
while True:
name=input('당신의 이름은 무엇입니까?:')
print(name,'님','안녕하세요?')
dice=random.randint(1,6)
if dice==1:
print('ㅇ.')
elif dice==2:
print('ㄴ.')
elif dice==3:
print('ㄹ.')
elif dice==4:
print('ㅎ.')
elif dice==5:
print('ㄱ.')
else:
print('ㅂ.')
print('감사합니다.')
input('시스템을 중지하시겠습니까?')
if answer=='Y'or'y':
break
elif answer=='N'or'n':
continue
코드는 이렇게 정했고, answer가 'Y'또는'y'를 눌러야만 break를 하고 싶은데 제목에 써져 있는 오류가 계속 반복이 되어서요. 어느 부분을 어떻게 수정해야 할까요..?
1 답변
-
break나 continue 명령은 루프 안에 존재해야 합니다.
import random while True: name=input('당신의 이름은 무엇입니까?:') print(name,'님','안녕하세요?') dice=random.randint(1,6) if dice==1: print('ㅇ.') elif dice==2: print('ㄴ.') elif dice==3: print('ㄹ.') elif dice==4: print('ㅎ.') elif dice==5: print('ㄱ.') else: print('ㅂ.') print('감사합니다.') input('시스템을 중지하시겠습니까?') if answer=='Y'or'y': break elif answer=='N'or'n': continue
댓글 입력