当前位置:   article > 正文

python编程超市购物系统_Python实现购物系统(示例讲解)

编写一个超市购物系统,要求能够录入商品单价信息,能够输入购物者购买物品情况

要求:

用户入口

1、商品信息存在文件里

2、已购商品,余额记录。

商家入口

可以添加商品,修改商品价格

Code:

商家入口:

# Author:P J J

import os

ps = '''

1 >>>>>> 修改商品

2 >>>>>> 添加商品

按q为退出程序

'''

# 打开两个文件,f文件为原来存取商品文件,f_new文件为修改后的商品文件

f = open('commodit', 'r', encoding='utf-8')

f_new = open('commodit_update', 'w+', encoding='utf-8')

file_list = f.readlines()

# 打印商品信息

while True:

productslist = []

# 从商品文件中读取出来的数据存放到productslist列表里

for line in file_list:

productname = line.strip().split()

productname, oldprice = line.strip("\n").split()

productslist.append([productname, int(oldprice)])

choose = input("%s请选择:" %ps)

if choose =='1':

for index, item in enumerate(productslist):

print(index, item)

productindex = input("请输入要修改价格的商品序号:")

if productindex.isdigit():

productindex = int(productindex)

while True:

print('要修改商品信息:', productslist[productindex])

price = input("请输入要修改的价格:")

if price.isdigit():

price = int(price)

productslist[productindex][1]=price

break

else:<

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/226591
推荐阅读
相关标签
  

闽ICP备14008679号