본문 바로가기

언어/Python

자판기 프로그램 만들기 !

coffee=3
cola=2
juice=1
coffeeMoney=1000
colaMoney=800
juiceMoney=700

while True:
    menu=input("메뉴를 입력하세요: ")
    moneyString=input("금액을 입력하세요: ")
    money=int(moneyString)

    if menu=="커피":
        print(menu)
        if money<coffeeMoney:
            print("돈이 부족합니다.")
            continue
        if coffee<=0:
            print("재고가 없습니다. 죄송합니다.")
            continue
        print("커피가 나왔습니다")
        coffee-=1
        print("커피가 "+ str(coffee) +"개 남았습니다.")

    elif menu=="콜라":
        print(menu)
        if money<colaMoney:
            print("돈이 부족합니다.")
            continue
        if cola<=0:
            print("재고가 없습니다. 죄송합니다.")
            continue
        print("콜라가 나왔습니다")
        cola-=1
        print("커피가 "+ str(cola) +"개 남았습니다.")


    elif menu=="주스":
        print(menu)
        if money<juiceMoney:
            print("돈이 부족합니다.")
            continue
        if juice<=0:
            print("재고가 없습니다. 죄송합니다.")
            continue
        print("커피가 나왔습니다")
        juice-=1
        print("커피가 "+ str(juice) +"개 남았습니다.")
#자판기 프로그램을 작성해보자
#기본 조건 : 잔돈 :5000원
#            재고 : 커피 3개, 콜라 2개, 쥬스 1개 

#입력 조건 메뉴 0: 커피 1 : 콜라 2 : 쥬스
# #             돈 1000 or 2000
#               커피 : 1000, 콜라 : 800, 쥬스 :700

# #출력조건 정상조건 : "커피(콜라. 쥬스) 가 나왔습니다."
#                         재고를 1개씩 소진한다
#                       재고 부족시 : 커피(콜라,쥬스)가 재고 소진되었습니다.
#                       투입 금액 부족시 : 돈이 부족합니다.
ord_money=5000
coffee_num=3
cola_num=2
juice_num=1
total=0
exit=100000
menu_cost=[1000,800,700]
menu_num=[coffee_num, cola_num, juice_num,exit]

print("커피 :1000원 콜라 : 800원 쥬스 : 700원")
while True:
    menu=input("0: 커피 1: 콜라 2: 쥬스 3:종료 몇번을 선택하시나요 >> ")
    cho=int(menu)
    if(menu_num[cho] ==0):
        print("재고가 소진되었습니다.다른 메뉴를 선택해주세요")

    if(cho==3):
        print("주문이 완료 되었습니다.")
        break
    menu_num[cho]=menu_num[cho]-1
    total+=menu_cost[cho]
   
total=str(total)
print("총 금액은 "+ total+ "입니다.")
input_total=0
money=0
total=int(total)
while True :
    input_money=input("돈을 넣으세요 / 1000원 or 2000원 ")
    cho=int(input_money)
    
    input_total=input_total+cho
    money=input_total-total
    
    if(input_total <total):
        print("돈이 부족합니다.")

    if(total-input_total>=ord_money):
        print("돈을 더이상 받지 않습니다.")
        break

money=str(money)
print(money+"돌려드립니다.")
    






#if(input_money)

'언어 > Python' 카테고리의 다른 글

외장함수  (0) 2019.11.25
내장함수  (0) 2019.11.25
반복문~ 함수~ 예외처리  (0) 2019.11.22
문자열~리스트~조건,반복문  (0) 2019.11.21
변수~문자열  (0) 2019.11.20