乙個簡單購物車的練習題

2021-08-14 18:59:16 字數 1049 閱讀 9612

# author:hemq

product_list = [

('蘋果手機',5800),

('蘋果電腦',9800),

('自行車',8000),

('手錶',10600),

('咖啡',31),

('python書籍',120)]

shopping_list =

salary = input("請輸入您的工資:")

if salary.isdigit():

salary = int(salary)

while true:

for index,item in enumerate(product_list):

print(index,item)

user_choice = input("請選擇商品》:")

if user_choice.isdigit():

user_choice = int(user_choice)

if user_choice < len(product_list) and user_choice >= 0:

p_item = product_list[user_choice]

if p_item[1] <= salary:

salary -= p_item[1]

print("新增商品:%s到你的購物車,您當前的餘額是:%s"%(p_item,salary))

else:

print("您的餘額不足...")

else:

print("您選擇的商品不存在...")

elif user_choice == 'q':

print("----------購物車列表---------")

for p in shopping_list:

print(p)

print("您的餘額是:",salary)

exit()

else:

print("錯誤選項")

else:

print("請輸入數字")

python3 練習題 購物車

購物車程式 需求 啟動程式後,讓使用者輸入工資,然後列印商品列表 允許使用者根據商品編號購買商品 使用者選擇商品後,檢測餘額是否夠,夠就直接扣款,不夠就提醒 使用者可一直購買商品,也可隨時退出,退出時列印已購的商和餘額 商品列表 product list iphone8 6888 macpro 14...

python 3 6練習題 仿購物車

opop iphone 9800 bike 800 mac pro 12000 定義商品列表 pyhon book 120 telas 429800 memory 7000 hard 4000 upan 90 shopping list salary input 請輸入你的工資 輸入工資 if sa...

乙個PHP購物車類

cart 購物車類 author doodoo package cart category cart license php license access public version revision 1.10 class cart reset item 這一句是必須的,因為上面的判斷已經移動了陣...