1. 程式人生 > >綜合練習[購物車]

綜合練習[購物車]

isdigit else 綜合練習 clas CA dig TE lis mac

product_list = [
    (Mac, 9000),
    (kindle, 800),
    (tesla, 900000),
    (python book, 105),
    (bike, 2000)
]

saving = input(please input your saving:)
shopping_car = []

if saving.isdigit():
    saving = int(saving)
    while True:

        for i,v in enumerate(product_list,1):
            print
(i,v) choice = input(選擇購買商品編號[退出:q]:) if choice.isdigit(): choice = int(choice) if choice > 0 and choice <= len(product_list): p_item = product_list[choice-1] if p_item[1] < saving: saving -= p_item[1] shopping_car.append(p_item)
else: print(余額不足, 還剩%s%saving) print(p_item) else: print(編碼不存在) elif choice == q: print(------您已經購買如下商品------) for i in shopping_car: print(i) print(您還剩%s元錢%saving)
break else: print("invalid input")

綜合練習[購物車]