import csv counts = {'不满意': 0, '一般': 0, '很满意': 0, '满意': 0} with open('result.txt', 'r') as a: f=a.read() key = f.split(',') for i in key: if i in counts: counts[i] += 1 with open('result.csv', 'w', encoding='gbk', newline='') as f: writer = csv.writer(f) writer.writerow(['评语', '次数']) for key, value in counts.items(): writer.writerow([key, value])变为python代码
时间: 2023-08-22 09:10:03 浏览: 65
auto_counts:自动计算课程满意度问卷调查结果
```python
import csv
counts = {'不满意': 0, '一般': 0, '很满意': 0, '满意': 0}
with open('result.txt', 'r') as a:
f = a.read()
key = f.split(',')
for i in key:
if i in counts:
counts[i] += 1
with open('result.csv', 'w', encoding='gbk', newline='') as f:
writer = csv.writer(f)
writer.writerow(['评语', '次数'])
for key, value in counts.items():
writer.writerow([key, value])
```
阅读全文