酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

Python实现:输入四季销量生成小商品企业年度销量统计报表

```python # 读取四个季度的销量 q1 = int(input()) q2 = int(input()) q3 = int(input()) q4 = int(input()) # 计算总销量 total = q1 + q2 + q3 + q4 # 计算每个季度的占比 ratio1 = q1 / total * 100 ratio2 = q2 / total * 100 ratio3 = q3 / total * 100 ratio4 = q4 / total * 100 # 输出报表 print(" Season Quantity Ratio") print("------------------------") print(f" Spring {q1:>8} {ratio1:6.1f}%") print(f" Summer {q2:>8} {ratio2:6.1f}%") print(f" Autumn {q3:>8} {ratio3:6.1f}%") print(f" Winter {q4:>8} {ratio4:6.1f}%") print("------------------------") print(f" Total {total:>8} {100.0:6.1f}%") ``` 1. 输入数据需要确保是整数,否则程序会报错。 2. 计算占比时使用浮点数除法,确保精度。 3. 输出格式使用f-string进行对齐,数字右对齐,保持美观。 ######[AI写代码神器 | 287点数解答 | 2025-08-01 14:03:32]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]