作业:制作电商购物程序

import jieba

import jieba.analyse


text = '''

'''


fenci_text = jieba.cut(text)

stopwords = {}.fromkeys([ line.rstrip() for line in open('stopwords.txt') ])

final = ""

for word in fenci_text:

if word not in stopwords:

if (word != "。" and word != ",") :

final = final + " " + word
print(final)

a=jieba.analyse.extract_tags(text, topK = 5, withWeight = True, allowPOS = ())

print(a)

(这些部分我不会是从百度网络上找的)

goods_dict = {


"001":{"name": "记事本", "price": 15},


"002":{"name": "钢笔", "price": 10},


"003":{"name": "橡皮擦", "price": 3},


"004":{"name": "尺子", "price": 6},


}

def goods_info():

print('-'*20+'打印商品列表:'+'-'*20)

print('商品编号\t商品名称\t商品价格')

for i in goods_dict.keys():

print("{} \t{} \t{}".format(i,goods_dict[i]['name'],goods_dict[i]['price']))

orders = []

i=0

def order_add():

global i

i =i + 1

good_index = input('请输入商品编号:')

while good_index not in goods_dict.keys():

good_index = input('请输入正确商品编号:')

else:

while 1:

try:

good_num = int(input('请输入商品数量:'))

except:

print('输入数量不符合数据格式!')

else:

break

order = { }

order['订单号:'] = i

order['商品名称:'] = goods_dict[good_index]['name']

order['单价:'] = goods_dict[good_index]['price']

order['购买数量:'] = good_num

orders.append(order)

print('你的订单如下:')

for item in orders:

print("订单编号:{} \t商品名称:{} \t 单价:{} \t购买数量:{}"

.format(item['订单号:'], item['商品名称:'], item['单价:'],item['购买数量:']))

is_keep= input('是否继续购物:(继续请输入yes)')

if is_keep== 'yes':

order_add()

else:

money = 0

for key in orders:

money += key['购买数量:']* key['单价:']

print('你的订单已提交,应付金额为%d元'%money)

pay = 0

while not pay ==money:

while 1:

try:

pay = int(input('请输入付款金额:'))

except:

print('请输入正确付款金额!')

else:

break

print('请输入正确付款金额!')

print('购物成功,欢迎再次光临!')


if __name__ == '__main__':

print('欢迎光临,我们提供如下产品供你购买:')

goods_info()

isbuy = input('是否购买商品:(购买请输入‘Buy’)')

if isbuy == 'yes':

order_add()

else:

print('谢谢你的光顾!')

quit()
(以下这些是我自己收集资料通过改写的)

猜你喜欢

转载自www.cnblogs.com/hzb1575016740/p/10888572.html