亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

python之購物車程序

標簽:
Python

题目: 购物车程序
业需求:
数据结构:
goods = [
{"name": "电脑", "price": 1999},
{"name": "鼠标", "price": 10},
{"name": "游艇", "price": 20},
{"name": "美女", "price": 998},
......
]

功能要求:
基础要求:
1、启动程序后,输入用户名密码后,让用户输入工资,然后打印商品列表
2、允许用户根据商品编号购买商品
3、用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
4、可随时退出,退出时,打印已购买商品和余额
5、在用户使用过程中, 关键输出,如余额,商品已加入购物车等消息,需高亮显示

扩展需求:
1、用户下一次登录后,输入用户名密码,直接回到上次的状态,即上次消费的余额什么的还是那些,再次登录可继续购买
2、允许查询之前的消费记录

基础功能实现:

goods = [{"name": "电脑", "price": 1999},{"name": "鼠标", "price": 10},{"name": "游艇", "price": 20},{"name": "美女", "price": 998},]goods.append("退出")name = input("what is your name:")password = input("input your password:")salary = int(input("how much your salary:"))for index,items in enumerate(goods):    print(index,items)cart=[]while True:    commodity = int(input("input goods what your want to buy:"))    if commodity >= len(goods):        print("your input number is over goods's price")        continue    elif commodity == int(len(goods) - 1):        # salary = salary - goods[commodity]["price"]        print("Your balance is \033[1;32m$% s\033[0m!" % salary)        print("your have buy some such as \033[1;32m% s\033[0m!" % cart)        break    else :        print(goods[commodity])        if goods[commodity]["price"] <= salary :            salary = salary - goods[commodity]["price"]            cart.append(goods[commodity])            print("\033[1;32mThe merchandise has been added to the shopping cart\033[0m!.Your balance is \033[1;32m$% s\033[0m!" % salary)        else:            print("You have \033[1;31m$% s\033[0m!, \033[1;31mYou don't have enough balance!!!\033[0m!" % salary)

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消