Esempio n. 1
0
import vending_machine.vending_service as machine  #模組名稱   將眾多function組成一個模組,模組在整合package

#建立物件導向 專案架構
flag = True  #while需放判斷式 True執行程式
from vending_machine.data import Drink

balance = 0
drinks = [
    Drink("可口可樂", 35),
    Drink("無糖茶裏王", 33),
    Drink("台鹽水", 36),
    Drink("貝納頌", 35),
    Drink("Dr. Milk", 40),
]


def deposit():  #function方法提出(將迴圈內部提出,inport進主程式
    global balance  #代表外面的balance,需要宣告 否者內部無法與外面對應
    value = eval(input("要放多少金額:"))
    while value < 1:
        print("=====儲存金額需大於零=====")
        value = eval(input("要放多少金額"))
    balance += value  #區域變數
    print(f"存完後餘額是{balance}元")  # f表示模組連結,非f表示字串顯示


def buy():  #function
    """
    儲值功能
    解釋程式碼用意
    :return:
Esempio n. 2
0
from vending_machine.data import Drink
balance = 0
drinks = [
    Drink('可樂', 20),
    Drink('雪碧', 20),
    Drink('茶裏王', 25),
    Drink('原萃', 25),
    Drink('純粹喝', 30),
    Drink('水', 20)
]


def deposit():
    """
    儲值功能
    :return:nothing
    """
    global balance
    value = eval(input("儲值金額:"))
    while value < 1:
        print("====儲值金額需要大於零====")
        value = eval(input("儲值金額:"))
    balance += value
    print(f'儲值後金額為{balance}')


def buy():
    """
    購買
    :return:nothing
    """
Esempio n. 3
0
from vending_machine.data import Drink
balance = 0
drinks = [
    Drink("可樂", 20),
    Drink("雪碧", 20),
    Drink("茶裏王", 25),
    Drink("原翠", 25),
    Drink("純粹喝", 30),
    Drink("水", 20),
]


def deposit():  # (要傳入的參數),如果不要回傳也可以不用()
    """
    儲值功能
    :return: nothing
    """
    global balance
    value = eval(input("儲值金額:"))
    while value < 1:
        print('====儲值金額需大於零====')
        value = eval(input("儲值金額:"))
    balance += value
    print(f"儲值後餘額為 {balance}元")


def buy():
    global balance
    # 印出品項
    print("\n請選擇商品")
    for i in range(0, len(drinks)):