作业2

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": 6.5},


"002":{"name": "饼干", "price": 10},


"003":{"name": "糖果", "price": 9},


"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()
(后面这里是自己收集资料改写而成)

posted @ 2019-05-19 03:11  xixi46  阅读(166)  评论(0)    收藏  举报