Python
19. while(반복문)
mimi04
2023. 5. 24. 13:03
customer = "토르"
index = 5
while index >=1: #while 조건: 어떤 조건이 만족할때까지 반복문
print("{0}, 커피가 준비 되었습니다. {1}번 남았습니다.".format(customer, index))
index -= 1 #index를 1씩 줄여나감
if index == 0:
print("커피는 폐기되었습니다.")
#무한루프
customer = "아이언맨"
index = 1
while True: #계속 부
print("{0},커피가 준비 되었습니다. 호출 {1}회".format(customer, index))
index += 1 #1씩 더함 #ctrl+c누르면 종료
#원하는 답이 나올때까지 반복
customer = "토르"
person = "Unknown"
while person != customer : #person 이름이 customer와 일치하지 않으면 계속 반복
print("{0}, 커피가 준비되었습니다.".format(customer))
person = input("이름이 어떻게 되세요? ")
반응형