본문 바로가기
프로그램

[파이썬] 문제 : 호텔 예약

by 오디세이99 2023. 2. 20.
728x90
반응형
print("=" * 30)
print('00호텔 예약 상담원입니다.')
print("=" * 30)

hotel = [0 for i in range(10)]   # 배열(리스트). 인덱스는 호실(인덱스는 0부터여서 인덱스+1로 함)

def reservation(h_lst, n):
    idx = h_lst.index(0)     # 0인 즉 비어있는 방 찾기
    h_lst[idx] = n           #   
    return idx              # 예약호실

def cancel(h_lst, n):
    idx = h_lst.index(n)     # n인 즉 예약된 호실 찾기
    h_lst[idx] = 0           # 0, 즉 비여있도록 함
    return idx              # 취소한 호실

def printRoom(h_lst):        # 각 호실별 예약 인원수 보이기
    for i in range(len(h_lst)):
        print('[',i+1,'] 인원수 : ',h_lst[i])

while True:
    why = input("무엇을 상담하시고 싶으십니까? ( 1. 호텔예약 2. 예약취소 3. 조회  9. 종료 ) ")
    if why == '1':
        num = input('인원 수를 적어주세요 ')
        room_no = reservation(hotel, num)
        print(num,'명 예약이 되었습니다.')
    elif why == '2':
        num = input('인원 수를 적어주세요 ')
        room_no = cencel(hotel, num)
        print(num,'명 예약이 취소되었습니다.')
    elif why == '3':
        printRoom(hotel)
    elif why == '9':
        print('종료합니다')
        break
    else:
        print("잘못 입력하셨습니다")
        continue

728x90
반응형

댓글