자판기 예제

2020. 2. 20. 00:40프로그래밍/Python

요구사항

1. 메뉴선택기능 -> 메뉴 출력
    1.커피  2.햄버거  3.돈가스  4.오므라이스
    입력받고 -> ex) 돈가스는 5천원입니다.
    돈을 넣어주세요 -> 6000
    주문되었습니다. 거스름돈은 1000원 입니다.


2. 설정메뉴
    1.메뉴 추가
    -> 이름 입력, 가격 입력
    2.메뉴 삭제

 

menu = ["커피", "햄버거", "돈까스", "오므라이스"]
price = ["1000", "3000", "4000", "7000"]

while True:

    print("1.메뉴선택 2.설정메뉴")
    c1 = input("번호 선택 >> ")
    if c1 == '1':
            print(menu)
            index = 0
            c2 = input("메뉴 입력: ")
            for i in menu:
                    if i == c2:
                            print(i + " 메뉴가 선택되었습니다.")
                            break
                    index += 1
            print("가격은 " + price[index])

            inp = int(input("돈을 넣어주세요. >> "))
            if inp >= int(price[index]):
                    inp = inp - int(price[index])
                    print("거스름 돈은 %d " % inp)
                    print("주문이 완료되었습니다.")
            elif inp < int(price[index]):
                    while True:
                            inp = int(price[index]) - inp
                            print("%d 원이 부족합니다" % inp)
                            inp2 = int(input("부족한 금액을 넣어주세요. >> "))
                            if inp == inp2 :
                                print("주문이 완료되었습니다.")
                                break
            
    elif c1 == '2':
            sel = input("1.메뉴 추가 2.메뉴삭제 >> ")

            if sel == '1':
                    new_menu = input("추가할 메뉴 입력 >> ")
                    new_price = input("추가한 메뉴 가격 입력 >> ")

                    menu.append(new_menu)
                    price.append(new_price)

                    print(new_menu + "를 추가 완료하였습니다.")

            elif sel == '2':
                    print(menu)
                    index = 0
                    c2 = input("삭제할 메뉴 입력 >> ")
                    for i in menu:
                            if i == c2:
                                    
                                    break
                            index += 1

                    menu.remove(c2)
                    price.pop(index)

                    print(c2 + "메뉴가 삭제되었습니다.")
        
                               
            

'프로그래밍 > Python' 카테고리의 다른 글

인적사항 정보 출력 프로그램  (0) 2020.02.20
팰린드롬 예제  (0) 2020.02.20
for, while 기본 연습  (0) 2020.02.20