购物车程序

Posted python-beginner

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了购物车程序相关的知识,希望对你有一定的参考价值。

#_*_coding:utf-8_*_
#作者:王佃元
#日期:2019/12/7
‘‘‘
购物车程序思路
1.涉及元素:用户账户、购物车、商品列表、商品价格
用户账户:存放用户余额
购物车:存放用户购买商品
商品列表:存放购物中心商品
商品价格:存放商品价格
商品编号:用于客户选择

流程
显示商品信息:包含商品名称、包含商品价格 需要使用格式化输出
显示用户输入对话框:用户账户余额输入
显示用户购买商品对话框:用户选择商品编号

‘‘‘
# iphone6s = 6800
# mac_book = 9000
# coffee = 32
# python_book = 80
# bicyle = 1500
# commodity_list = ["iphone6s","mac book","coffee","python book","bicyle"]
# commodity_price = [6800,9000,32,80,1500]
# shopping_car = []
# # price_list = [6800,9000,32,80,1500]
# product_list = ‘‘‘
# ---------------shopping list---------------
# 1. %s %d
# 2. %s %d
# 3. %s %d
# 4. %s %d
# 5. %s %d
# -------enter number to purchase------------
# ‘‘‘% (commodity_list[0], commodity_price[0], commodity_list[1], commodity_price[1], commodity_list[2], commodity_price[2], commodity_list[3], commodity_price[3], commodity_list[4], commodity_price[4])
# print(product_list)
#
# user_salary = int(input("please enter your salary : "))
#
# user_not_quit = True
# while user_not_quit:
# prodcut_num = int(input("please enter the number : "))
# if user_salary < commodity_price[prodcut_num-1]:
# print("sorry,the salary is not enough!")
# # print(commodity_price[prodcut_num])
# else:
# # print(commodity_list[prodcut_num-1])
# shopping_car.append(commodity_list[prodcut_num-1]) #获取商品并加入购物车
# user_salary = user_salary - commodity_price[prodcut_num-1] #获取购买商品后剩余金额
# # shopping_car.index("iphone6s")
# print(‘‘‘
# the shopping car : %s
# you account balance : %d‘‘‘%(shopping_car[0:],user_salary))
# quit_or_continue = input("enter ‘q‘ quit or enter any continue : ")
# if quit_or_continue == "q":
# print(‘‘‘
# you have buy commodity : %s
# you account balance : %d
# welcom back!
# ‘‘‘%(shopping_car,user_salary)
# )
# break
# prodcut_num = int(input("please enter the number again : "))
commodity_list = [["iphone6s",6800],["mac book",9000],["coffee",32],["python book",80],["bicyle",1500]]
shopping_car = []
for product_list in commodity_list:
# price_list = [6800,9000,32,80,1500]
product_list = ‘‘‘%d> %s %d‘‘‘% (commodity_list.index(product_list)+1,product_list[0],product_list[1])
print(product_list,end=" ")

user_salary = int(input("please enter your salary : "))
while True:
prodcut_num = int(input("please enter the number : "))
if user_salary < commodity_list[prodcut_num-1][1]:
print("sorry,the salary is not enough!")
else:
shopping_car.append(commodity_list[prodcut_num-1][0]) #获取商品并加入购物车
user_salary = user_salary - commodity_list[prodcut_num-1][1] #获取购买商品后剩余金额
# shopping_car.index("iphone6s")
print(‘‘‘
the shopping car : %s
you account balance : %d
‘‘‘%(shopping_car[0:],user_salary))
quit_or_continue = input("enter ‘q‘ quit or enter any continue : ")
if quit_or_continue == "q":
print(‘‘‘
you have buy commodity : %s
you account balance : %d
welcome back!
‘‘‘%(shopping_car,user_salary))
break

以上是关于购物车程序的主要内容,如果未能解决你的问题,请参考以下文章

购物车程序

微信小程序转载:微信小程序之购物车功能

微信小程序 将商品添加到购物车 数据怎么存

popmart小程序怎样加购物车

购物车的程序设计

程序练习2:购物车程序