```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进行对齐,数字右对齐,保持美观。 [2025-08-01 14:03:32 | AI写代码神器 | 287点数解答]