品牌对比|康师傅 VS 统一

在这里插入图片描述

品牌名:康师傅

品牌类别:食品类

榜单:品牌声量榜周榜第3名

对比时间:2021-07-29

品牌名:统一

品牌类别:食品类

榜单:品牌声量榜周榜第2名

对比时间:2021-07-29

品牌对比仅仅展示 30 天数据对比结果,以下数据来源于西瓜微数,仅供参考。

01
数据概览对比

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Python中的文件操作来实现商品信息的持久存储。具体实现步骤如下: 1. 定义一个商品类,用于存储商品名称、单价和购买数量。 2. 定义一个函数,用于将商品信息写入文件中。 3. 定义一个函数,用于从文件中读取商品信息并打印。 4. 在主程序中实现用户交互,获取用户输入的商品信息,并调用写入文件的函数将商品信息存储起来。 5. 在主程序中实现循环读取文件中的商品信息,并计算金额小计并打印。 代码实现如下: ```python import os # 定义商品类 class Product: def __init__(self, name, price, quantity): self.name = name self.price = price self.quantity = quantity def subtotal(self): return self.price * self.quantity # 将商品信息写入文件 def write_to_file(product): with open('products.txt', 'a') as f: f.write(f"{product.name},{product.price},{product.quantity}\n") # 从文件中读取商品信息并打印 def print_products(): print("商品名称\t商品单价\t购买数量\t金额小计") total = 0 with open('products.txt', 'r') as f: for line in f: name, price, quantity = line.strip().split(',') price = float(price) quantity = int(quantity) subtotal = price * quantity total += subtotal print(f"{name}\t\t¥{price}\t\t{quantity}\t\t¥{subtotal}") print(f"总计金额:¥{total}") while True: name = input("请输入购买的商品名称:【】") price = float(input("请输入购买的商品单价:【】")) quantity = int(input("请输入购买的商品数量:【】")) product = Product(name, price, quantity) write_to_file(product) choice = input("是否继续结账下一种商品(yes/no):【】") if choice.lower() == 'no': break print_products() ``` 在执行程序时,会先提示用户输入商品信息,然后询问是否继续结账下一种商品。如果用户选择继续,则会再次提示用户输入商品信息,直到用户选择不再记录为止。最后,程序会从文件中读取商品信息并打印,计算出总计金额并输出。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值