본문 바로가기

Python

19. while(반복문)

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("이름이 어떻게 되세요? ")
반응형

'Python' 카테고리의 다른 글

21. 한 줄 for  (0) 2023.05.24
20. continue/ break  (0) 2023.05.24
18. for(반복문)  (0) 2023.05.22
17. if(조건문)  (0) 2023.05.22
16. shuffle , sample  (0) 2023.05.22