본문 바로가기
language/Python

[Python] 파이썬 while문 반복문

by By the Ronys 2020. 8. 26.
반응형

customer = "토르"
index = 5
while index >= 1 : #어떤 조건이 만족할 때 까지 반복하는 문 / 만족하면 탈출
print("{0}, 커피가 준비되었습니다. {1} 번 남았어요.".format(customer, index))
index -= 1
if index == 0 :
print("커피는 폐기 처분되었습니다.")

customer = "아이언맨"
index = 1
while True :  # 무한루프
print("{0}, 커피가 준비되었습니다. 호출 {1} 회.".format(customer, index))
index += 1

customer = "헐크"
person = "Unknown"

while person != customer : # person이 customer와 같지 않을때 반복하는것 / 반대로 같아지면 탈출하고 종료
print("{0}, 커피가 준비되었습니다. ".format(customer))
person = input("이름이 어떻게 되세요?") # 헐크 입력하는 순간 person 과 customer 같아지므로 while문 종료

 

댓글