#메뉴판 이미지 추가 #클래스 생성함 (클래스 이름: Coffee_Class) class Coffee_Class(): def __init__(self): self.aaa("c:\\data\\kiosk.png") print('커피 키오스크 시스템을 시작합니다.')
def aaa(self,name): import PIL.Image as pilimg import numpy as np import matplotlib.pyplot as plt
im = pilimg.open(name) pix = np.array(im) plt.imshow(pix) plt.axis('off') plt.show()
def coffee_kiosk(self): #7. 이미지 저장 self.aaa("c:\\data\\coffee.png") import pandas as pd
# 1.딕셔너리 생성 cafe_dict = {} cafe_dict['주문번호']=[] cafe_dict['주문시간']=[] cafe_dict['주문메뉴']=[] cafe_dict['주문수량']=[] cafe_dict['결제금액']=[]
# 2.커피종류, 커피재고, 커피가격을 리스크 또는 튜플화 # if문을 여러번 나열하지 않고 코드를 단순화하기 위함 menu=('아메리카노','카페라떼','카페모카','녹차라떼') stock=[20,10,30,20] price=(1500,2500,3500,3500) coupon=0 order_no=0
# 3.메뉴판 출력 print('='*21,'MENU','='*21) self.aaa("c:\\data\\cafe_menu.png")#메뉴판 이미지 print('='*48)
# 4.주문 프로그램 시작 while True:
# 4-1.전체 품절 if stock[0] == 0 and stock[1] == 0 and stock[2] == 0 and stock[3] == 0: print('죄송합니다. 전 상품 품절되었습니다.') break
num = int(input('▶ 주문하시겠습니까? 메뉴 번호를 입력해주세요.: '))
# 4-2.커피 주문 if num < 5: print('%s를 선택하셨습니다.'%menu[num-1]) if stock[num-1] == 0 : print('죄송합니다. %s가 품절되었습니다. \n다른 상품으로 고르시겠습니까?' %menu[num-1]) print('▷ 주문 가능 수량 : \n%s %d잔, %s %d잔, %s %d잔'%(menu[0],stock[0],menu[1],stock[1],menu[2],stock[2])) print('='*48) continue print('(현재 주문 가능한 수량은 %d잔입니다.)'%stock[num-1]) cup = int(input('▶ 몇 잔 주문하시겠습니까? ')) if cup > stock[num-1]: print('죄송합니다. 주문량에 비해 %s가 부족합니다.\n다시 입력해주세요'%menu[num-1]) print('='*48) continue print('▶ 결제하실 금액은 %d원입니다.'%(cup*price[num-1])) money = int(input('돈을 넣어주세요~ ')) if money >= cup*price[num-1]: order_no += 1 print('-'*48) print('주문번호 %d번님, %s %d잔 나왔습니다. \n거스름돈은 %d원입니다' %(order_no,menu[num-1],cup,money-(cup*price[num-1]))) print('-'*48) stock[num-1] -= cup coupon += cup else: print('죄송합니다. %d원이 부족합니다. \n돈을 돌려드리겠습니다.' %((cup*price[num-1])-money)) print('='*48) continue # 4-3.주문 데이터 쌓기 (함수 사용 X) from datetime import datetime now=str(datetime.now()) cafe_dict['주문번호'].append(order_no) cafe_dict['주문시간'].append(now[0:19]) cafe_dict['주문메뉴'].append(menu[num-1]) cafe_dict['주문수량'].append(cup) cafe_dict['결제금액'].append(cup*price[num-1])
# 4-4.주문 완료시 출력되는 메시지 print('쿠폰이 %d개가 발행되었습니다. \n(20개를 모으면 한잔 무료)' %cup) print('='*48) print('▷ 주문 가능 수량 : \n%s %d잔, %s %d잔, %s %d잔'%(menu[0],stock[0],menu[1],stock[1],menu[2],stock[2])) print('='*48)
# 4-5.주문정산 elif num == 5: secr_num = int(input('비밀번호를 입력하세요: ')) if secr_num == 1234: print('='*48,'\n [관리자 전용] 정산내역을 출력합니다.') break else: print('비밀번호가 잘못 입력되었습니다.\n초기화면으로 돌아갑니다.') continue
# 4-6.메뉴 번호 잘못 입력한 경우 else: print('번호를 잘못 입력하셨습니다. 다시 입력해주세요.') continue
# 5. 주문정산 내역 판다스로 출력 from datetime import datetime now = str(datetime.now()) cafe = pd.DataFrame(cafe_dict) cafe.to_csv("c:\\data\\coffee_report_"+ now[0:10] + '일_' + now[11:13] + '시_' + now[14:16] + '분_' + now[17:19] +'초' +".csv", encoding="ANSI")# 또는 UTF-8 print ('지금까지 번 총 수익은', cafe['결제금액'].sum()) #6. 그래프 추가 import pandas as pd from matplotlib import font_manager, rc import matplotlib.pyplot as plt font_name = font_manager.FontProperties(fname="c:/Windows/Fonts/malgun.ttf").get_name() rc('font', family=font_name) result=cafe.groupby('주문메뉴')['결제금액'].sum().reset_index() result.columns=['메뉴','합계'] result.plot.pie(y='합계',labels=result['메뉴'], autopct='%1.1f%%') plt.legend(loc='lower center',bbox_to_anchor=(1, 1)) #. 원형 그래프 저장(result 일시분초..) from datetime import datetime now = str(datetime.now()) plt.legend(loc='best',bbox_to_anchor=(1, 1)) plt.savefig('c:\\data\\result_'+ now[0:10] + '일_' + now[11:13] + '시_' + now[14:16] + '분_' + now[17:19] +'초' +'.png', dpi=300) return cafe |