写一个python程序打印如下内容------------------------------------------------------------ 商品编号 商品名称 价格 生产日期 12550531 Python程序设计 80.00 2019/01/01 ------------------------------------------------------------
时间: 2023-08-15 18:16:57 浏览: 94
以下是一个简单的打印商品信息的 Python 代码示例:
```python
# 定义商品信息
product = {"编号": "12550531", "名称": "Python程序设计", "价格": 80.00, "生产日期": "2019/01/01"}
# 打印商品信息表头
print("{:-^80}".format(" 商品信息表 "))
print("{:<10}{:<30}{:<10}{}".format("商品编号", "商品名称", "价格", "生产日期"))
# 打印商品信息
print("{:<10}{:<30}{:<10.2f}{}".format(product["编号"], product["名称"], product["价格"], product["生产日期"]))
# 打印商品信息表结束语
print("{:-^80}".format(" 商品信息表打印完毕! "))
```
输出结果为:
```
----------------------------------- 商品信息表 -----------------------------------
商品编号 商品名称 价格 生产日期
12550531 Python程序设计 80.00 2019/01/01
-------------------------- 商品信息表打印完毕! ---------------------------
```
你可以将商品信息字典中的内容替换为你自己的商品信息。注意,这里使用了字符串的 format() 方法来进行字符串格式化,其中 "<" 表示左对齐,"{}" 表示占位符,"10" 表示占位符宽度为 10 个字符,".2f" 表示保留两位小数。字符串.format() 方法中的 ":" 用于格式化输出。
阅读全文
相关推荐
















