From 1490ad30ab9a16bb6f0295b34c897aa030de5c8a Mon Sep 17 00:00:00 2001 From: TrixieL20 Date: Sun, 26 Nov 2023 14:01:11 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[B=ED=8C=80=20-=20=EC=9D=B4=EB=AF=BC?= =?UTF-8?q?=EC=A0=95]=201=EC=B0=A8=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vending.py | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 vending.py diff --git a/vending.py b/vending.py new file mode 100644 index 0000000..6879572 --- /dev/null +++ b/vending.py @@ -0,0 +1,117 @@ +def select_temperature(): + print("[어서와요! GDSC 음료 자판기]") + input("사용자 입력 > ") + print("------------------------------") + print("음료를 선택 해주세요!\n") + print("[1] 차가운 음료\n[2] 따뜻한 음료\n") + temperature = (input("사용자 입력 > ")) + print("\n------------------------------") + return temperature + +def cold(juice_list, price_list): + print("[차가운 음료]\n") + print("[1] 스프라이트 : 1,500원") + print("[2] 코카콜라 : 1,300원") + print("[3] 솔의눈 : 1,000원") + print("[4] 펩시 콜라 : 1,100원\n") + juice = int(input("사용자 입력 > ")) + if (juice < 1 or juice > 4): + print("잘못 입력하셨으므로 자판기가 종료됩니다.") + exit + print("\n------------------------------") + return juice_list[juice - 1], price_list[juice - 1] + +def hot(juice_list, price_list): + print("[차가운 음료]\n") + print("[1] TOP커피 : 1,800원") + print("[2] 꿀물 : 1,500원") + print("[3] 홍삼차 : 1,700원") + print("[4] 단팥죽 :2,100원\n") + juice = int(input("사용자 입력 > ")) + print("\n------------------------------") + return juice_list[juice + 3], price_list[juice + 3] + +def add_juice(): + print("[관리자 페이지 - 음료 관리]\n") + +def select_pay(): + print("[결제 방식 선택]\n") + print("[1] 현금") + print("[2] 카드 (부가세 10% 적용)\n") + payment = int(input("사용자 입력 > ")) + print("\n------------------------------") + return payment + +def cash(sum, price, cash_list): + while(sum < price): + print("[현금 투입 : {}원]\n".format(sum)) + print("[1] 5만원권") + print("[2] 1만원권") + print("[3] 5천원권") + print("[4] 1천원권") + print("[5] 500원") + print("[6] 100원") + print("[0] 반환\n") + num = int(input("사용자 입력 > ")) + print("\n------------------------------") + + if (num == 0): + sum = 0 + elif (num >= 1 and num <= 6): + sum += cash_list[num - 1] + else: + print("잘못 입력하셨으므로 자판기가 종료됩니다.") + exit + return sum + +def cal(change, cash_list): + ret = [] + for cash in cash_list: + ret.append(change // cash) + change %= cash + return ret + +def main(): + price_list = [1500, 1300, 1000, 1100, 1800, 1500, 1700, 2100] + juice_list = ["스프라이트", "코카콜라", "솔의눈", "펩시 콜라", "TOP커피", "꿀물", "홍삼차", "단팥죽"] + cash_list = [50000, 10000, 5000, 1000, 500, 100] + + temperature = select_temperature() + + if (temperature == "1"): + juice, price = cold(juice_list, price_list) + print(juice) + elif (temperature == "2"): + juice, price = hot(juice_list, price_list) + print(juice) + else: + print("잘못 입력하셨으므로 자판기가 종료됩니다.") + exit + + payment = select_pay() + + if (payment == 1): + sum = cash(0, price, cash_list) + ret = cal(sum - price, cash_list) + + print("\n------------------------------") + print("이용해주셔서 감사합니다.\n") + print("[주문 음료]\n{}\n".format(juice)) + + if (payment == 1): + pay = str(sum) + pay = pay[:-3] + "," + pay[-3:] + print("[투입 금액]\n{}원\n".format(pay)) + print("[잔돈]\n") + for i in range(len(cash_list)): + if (ret[i] != 0): + print("{}원 동전 : {}개\n".format(cash_list[i], ret[i])) + elif (payment == 2): + pay = str(int(price * 1.1)) + pay = pay[:-3] + "," + pay[-3:] + print("[결제 금액]\n{}원".format(pay)) + else: + print("잘못 입력하셨으므로 자판기가 종료됩니다.") + exit + +main() \ No newline at end of file From d94af110424bdcb1e9dd18a6b8614a012a9589b6 Mon Sep 17 00:00:00 2001 From: TrixieL20 <102663507+TrixieL20@users.noreply.github.com> Date: Sun, 26 Nov 2023 15:56:18 +0900 Subject: [PATCH 2/3] Update vending.py --- vending.py | 134 +++++++++++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 60 deletions(-) diff --git a/vending.py b/vending.py index 6879572..d607adb 100644 --- a/vending.py +++ b/vending.py @@ -8,31 +8,27 @@ def select_temperature(): print("\n------------------------------") return temperature -def cold(juice_list, price_list): +def cold(juice_list, price_list, cold_idx): print("[차가운 음료]\n") - print("[1] 스프라이트 : 1,500원") - print("[2] 코카콜라 : 1,300원") - print("[3] 솔의눈 : 1,000원") - print("[4] 펩시 콜라 : 1,100원\n") + for i in range(cold_idx): + price = str(price_list[i]) + price = price[:-3] + "," + price[i][-3:] + print(f"[{i + 1}] {juice_list[i]} : {price}원") juice = int(input("사용자 입력 > ")) - if (juice < 1 or juice > 4): - print("잘못 입력하셨으므로 자판기가 종료됩니다.") - exit + if (juice < 1 or juice > cold_idx): + error_handle() print("\n------------------------------") return juice_list[juice - 1], price_list[juice - 1] -def hot(juice_list, price_list): +def hot(juice_list, price_list, cold_idx): print("[차가운 음료]\n") - print("[1] TOP커피 : 1,800원") - print("[2] 꿀물 : 1,500원") - print("[3] 홍삼차 : 1,700원") - print("[4] 단팥죽 :2,100원\n") - juice = int(input("사용자 입력 > ")) + for i in range(len(juice_list) - cold_idx): + price = str(price_list[i + cold_idx]) + price = price[:-3] + "," + price[-3:] + print(f"[{i + 1}] {juice_list[i + cold_idx]} : {price}원") + juice = int(input("\n사용자 입력 > ")) print("\n------------------------------") - return juice_list[juice + 3], price_list[juice + 3] - -def add_juice(): - print("[관리자 페이지 - 음료 관리]\n") + return juice_list[juice + cold_idx - 1], price_list[juice + cold_idx - 1] def select_pay(): print("[결제 방식 선택]\n") @@ -42,76 +38,94 @@ def select_pay(): print("\n------------------------------") return payment -def cash(sum, price, cash_list): - while(sum < price): - print("[현금 투입 : {}원]\n".format(sum)) - print("[1] 5만원권") - print("[2] 1만원권") - print("[3] 5천원권") - print("[4] 1천원권") - print("[5] 500원") - print("[6] 100원") - print("[0] 반환\n") - num = int(input("사용자 입력 > ")) - print("\n------------------------------") +def cash_input(sum): + print(f"[현금 투입 : {sum}원]\n") + print("[1] 5만원권") + print("[2] 1만원권") + print("[3] 5천원권") + print("[4] 1천원권") + print("[5] 500원") + print("[6] 100원") + print("[0] 반환\n") + num = int(input("사용자 입력 > ")) + print("\n------------------------------") + return num + +#ui와 분리.. +def cash_calculate(sum, price, cash_list): + while (sum < price): + num = cash_input(sum) if (num == 0): sum = 0 elif (num >= 1 and num <= 6): sum += cash_list[num - 1] else: - print("잘못 입력하셨으므로 자판기가 종료됩니다.") - exit + error_handle() return sum -def cal(change, cash_list): +def change_calculate(change, cash_list): ret = [] for cash in cash_list: ret.append(change // cash) change %= cash return ret +def change_print(cash_list, ret): + print("[잔돈]\n") + for i in range(len(cash_list)): + if (ret[i] != 0): + print(f"{cash_list[i]}원 동전 : {ret[i]}개\n") + +def error_handle(): + print("잘못 입력하셨으므로 자판기가 종료됩니다.") + exit + +def cash_output(juice, sum, cash_list, ret): + print("\n------------------------------") + print("이용해주셔서 감사합니다.\n") + print(f"[주문 음료]\n{juice}\n") + + pay = str(sum) + pay = pay[:-3] + "," + pay[-3:] + print(f"[투입 금액]\n{pay}원\n") + change_print(cash_list, ret) + +def card_output(juice, price): + print("\n------------------------------") + print("이용해주셔서 감사합니다.\n") + print(f"[주문 음료]\n{juice}\n") + + pay = str(int(price * 1.1)) + pay = pay[:-3] + "," + pay[-3:] + print(f"[결제 금액]\n{pay}원") + + def main(): price_list = [1500, 1300, 1000, 1100, 1800, 1500, 1700, 2100] juice_list = ["스프라이트", "코카콜라", "솔의눈", "펩시 콜라", "TOP커피", "꿀물", "홍삼차", "단팥죽"] cash_list = [50000, 10000, 5000, 1000, 500, 100] temperature = select_temperature() + cold_idx = 4 if (temperature == "1"): - juice, price = cold(juice_list, price_list) - print(juice) + juice, price = cold(juice_list, price_list, cold_idx) elif (temperature == "2"): - juice, price = hot(juice_list, price_list) - print(juice) + juice, price = hot(juice_list, price_list, cold_idx) else: - print("잘못 입력하셨으므로 자판기가 종료됩니다.") - exit + error_handle() payment = select_pay() if (payment == 1): - sum = cash(0, price, cash_list) - ret = cal(sum - price, cash_list) - - print("\n------------------------------") - print("이용해주셔서 감사합니다.\n") - print("[주문 음료]\n{}\n".format(juice)) - - if (payment == 1): - pay = str(sum) - pay = pay[:-3] + "," + pay[-3:] - print("[투입 금액]\n{}원\n".format(pay)) - print("[잔돈]\n") - for i in range(len(cash_list)): - if (ret[i] != 0): - print("{}원 동전 : {}개\n".format(cash_list[i], ret[i])) + sum = cash_calculate(0, price, cash_list) + print(price) + ret = change_calculate(sum - price, cash_list) + cash_output(juice, sum, cash_list, ret) elif (payment == 2): - pay = str(int(price * 1.1)) - pay = pay[:-3] + "," + pay[-3:] - print("[결제 금액]\n{}원".format(pay)) + card_output(juice, price) else: - print("잘못 입력하셨으므로 자판기가 종료됩니다.") - exit + error_handle() -main() \ No newline at end of file +main() From 17586e3131b2f0d6cf6e9576a4427540495dc86e Mon Sep 17 00:00:00 2001 From: TrixieL20 <102663507+TrixieL20@users.noreply.github.com> Date: Sun, 26 Nov 2023 16:44:16 +0900 Subject: [PATCH 3/3] Update vending.py --- vending.py | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/vending.py b/vending.py index d607adb..93edc12 100644 --- a/vending.py +++ b/vending.py @@ -30,6 +30,15 @@ def hot(juice_list, price_list, cold_idx): print("\n------------------------------") return juice_list[juice + cold_idx - 1], price_list[juice + cold_idx - 1] +def handle_juice(temperature, juice_list, cold_idx): + if (temperature == "1"): + juice, price = cold(juice_list, price_list, cold_idx) + return juice, price + elif (temperature == "2"): + juice, price = hot(juice_list, price_list, cold_idx) + return juice, price + error_handle() + def select_pay(): print("[결제 방식 선택]\n") print("[1] 현금") @@ -51,7 +60,6 @@ def cash_input(sum): print("\n------------------------------") return num -#ui와 분리.. def cash_calculate(sum, price, cash_list): while (sum < price): num = cash_input(sum) @@ -60,7 +68,7 @@ def cash_calculate(sum, price, cash_list): sum = 0 elif (num >= 1 and num <= 6): sum += cash_list[num - 1] - else: + elif (num < 0 or num > 6): error_handle() return sum @@ -81,7 +89,7 @@ def error_handle(): print("잘못 입력하셨으므로 자판기가 종료됩니다.") exit -def cash_output(juice, sum, cash_list, ret): +def cashpay_output(juice, sum, cash_list, ret): print("\n------------------------------") print("이용해주셔서 감사합니다.\n") print(f"[주문 음료]\n{juice}\n") @@ -91,7 +99,7 @@ def cash_output(juice, sum, cash_list, ret): print(f"[투입 금액]\n{pay}원\n") change_print(cash_list, ret) -def card_output(juice, price): +def cardpay_output(juice, price): print("\n------------------------------") print("이용해주셔서 감사합니다.\n") print(f"[주문 음료]\n{juice}\n") @@ -100,6 +108,17 @@ def card_output(juice, price): pay = pay[:-3] + "," + pay[-3:] print(f"[결제 금액]\n{pay}원") +def handle_payment(payment, juice, price, sum, cash_list, ret): + if (payment == 1): + sum = cash_calculate(0, price, cash_list) + print(price) + ret = change_calculate(sum - price, cash_list) + cashpay_output(juice, sum, cash_list, ret) + return + elif (payment == 2): + cardpay_output(juice, price) + return + error_handle() def main(): price_list = [1500, 1300, 1000, 1100, 1800, 1500, 1700, 2100] @@ -109,23 +128,8 @@ def main(): temperature = select_temperature() cold_idx = 4 - if (temperature == "1"): - juice, price = cold(juice_list, price_list, cold_idx) - elif (temperature == "2"): - juice, price = hot(juice_list, price_list, cold_idx) - else: - error_handle() - + juice, price = handle_juice(temperature, juice_list, cold_idx) payment = select_pay() - - if (payment == 1): - sum = cash_calculate(0, price, cash_list) - print(price) - ret = change_calculate(sum - price, cash_list) - cash_output(juice, sum, cash_list, ret) - elif (payment == 2): - card_output(juice, price) - else: - error_handle() + handle_payment(payment, juice, price, sum, cash_list, ret) main()