Skip to content

Commit

Permalink
Update vending.py
Browse files Browse the repository at this point in the history
  • Loading branch information
alstjr7437 committed Nov 26, 2023
1 parent 9baf6c9 commit b4684ab
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions vending.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import math

def int_check(i):
try:
return(int(i))
except ValueError:
return int_check(input("문자열이 입력됐습니다! 다시 입력해주세요 > "))

# 주문 함수
def order_drink():
global menu

print("음료를 선택 해주세요!\n[1] 차가운 음료\n[2] 따뜻한 음료")
menu_type = int(input("사용자 입력 > "))
menu_type = int_check(input("사용자 입력 > "))
print("-------------------------------")
if menu_type == 1:
print("[차가운 음료]")
Expand All @@ -14,19 +20,26 @@ def order_drink():
print("[따듯한 음료]")
menu = menu["따듯한 음료"]
else:
print("잘못된 메뉴 유형입니다.")
return None, 0
print("잘못된 입력입니다!!")
return order_drink()

selected_drink, selected_price = select_menu()

return selected_drink, selected_price

# 메뉴 보여주기 및 선택 함수
def select_menu():
num_item = 0
for i, (drink, price) in enumerate(menu.items(), start=1):
print(f"[{i}] {drink} : {price}원")
num_item += 1

user_choice = int_check(input("사용자 입력 > "))

user_choice = int(input("사용자 입력 > "))
if (user_choice >= 1 and user_choice <= num_item) == False:
print("-------------------------------\n 잘못된 입력입니다. 다시 입력해주세요!")
return select_menu()

selected_drink = list(menu.keys())[user_choice - 1]
selected_price = menu[selected_drink]

Expand All @@ -36,12 +49,15 @@ def select_menu():
def payment_task(selected_drink, selected_price):
print("[결제 방식 선택]")
print("[1] 현금\n[2] 카드 (부가세 10% 적용)")
payment_method = int(input("사용자 입력 > "))
payment_method = int_check(input("사용자 입력 > "))
if payment_method == 1 :
cash_pay(selected_drink, selected_price)
if payment_method == 2 :
elif payment_method == 2 :
selected_price += selected_price / 10
print(f"-------------------------------\ns이용해주셔서 감사합니다. \n\n[주문 음료]\n{selected_drink}\n\n[결제 금액]\n{math.trunc(selected_price)}원")
else :
print("지원하는 결제 방식이 아닙니다! 다시 입력해주세요!")
return payment_task(selected_drink, selected_price)

# 현금 결제
def cash_pay(selected_drink, selected_price) :
Expand All @@ -50,27 +66,30 @@ def cash_pay(selected_drink, selected_price) :
print("-------------------------------")
print(f"[현금 투입 : {total_cash}원]")
print("[1] 5만원권\n[2] 1만원권\n[3] 5천원권\n[4] 1천원권\n[5] 500원\n[6] 100원\n[0] 반환")
cash_input = int(input("사용자 입력 > "))
cash_input = int_check(input("사용자 입력 > "))

if cash_input == 0:
total_cash = 0
elif cash_input >= 1 and cash_input <= 6:
print("")
else :
continue

cash_values = [50000, 10000, 5000, 1000, 500, 100, 0]
total_cash += cash_values[cash_input - 1]

print("-------------------------------\n이용해주셔서 감사합니다.\n")
print(f"[주문 음료] \n{selected_drink}\n")
print(f"[투입 금액] \n{total_cash}\n")

change = total_cash - selected_price
change_units = [500, 100]
print("[잔돈]")
for unit in change_units:
count = change // unit
change %= unit
if count > 0:
print(f"{unit}원 동전 : {count}개")
print("-------------------------------\n이용해주셔서 감사합니다.\n")
print(f"[주문 음료] \n{selected_drink}\n")
print(f"[투입 금액] \n{total_cash}\n")

change = total_cash - selected_price
print("[잔돈]")
change_units = [50000, 10000, 5000, 1000, 500, 100]
for unit in change_units:
count = change // unit
change %= unit
if count > 0:
print(f"{unit}원권 : {count}개")

# 매니저 부분
def manager_task():
Expand All @@ -83,7 +102,7 @@ def main():
# 시작
input("[어서와요! GDSC 음료 자판기]\n 계속 하려면 아무키나 입력하세요 ...")
print("-------------------------------\n[사용자 선택]\n[1] 사용자\n[2] 관리자\n[3] 종료")
Task_menu = int(input("사용자 입력 > "))
Task_menu = int_check(input("사용자 입력 > "))
print("-------------------------------")
if Task_menu == 1 :
print("[사용자]")
Expand All @@ -94,7 +113,6 @@ def main():
print("잘못 입력하셨습니다!")
return 0


selected_drink, selected_price = order_drink()

print(f"-------------------------------\n[주문 음료] {selected_drink}\n")
Expand Down

0 comments on commit b4684ab

Please sign in to comment.