用pathon写一段代码随机生成90个食堂饭菜调查结果,学生可以用“很满意,满意,一般,不满意”之一做出评价,统计4类意见的数目,以及出现最多的意见数目。
时间: 2024-05-12 22:18:06 浏览: 37
pathon爬虫-豆瓣电影TOP250_handle8tt_爬虫_爬虫电影_pathon_
当然,我会很乐意为您编写这样的代码。以下是一个简单的Python代码示例,可以随机生成90个假定的调查结果,并记录4种意见出现的次数,以及最常见的意见数目:
``` python
import random
# 定义四种意见常量
VERY_SATISFIED = "Very Satisfied"
SATISFIED = "Satisfied"
AVERAGE = "Average"
UNSATISFIED = "Unsatisfied"
# 生成 90 个假定的调查结果
survey_results = [random.choice([VERY_SATISFIED, SATISFIED, AVERAGE, UNSATISFIED]) for _ in range(90)]
# 统计四类意见出现的数目
very_satisfied_count = survey_results.count(VERY_SATISFIED)
satisfied_count = survey_results.count(SATISFIED)
average_count = survey_results.count(AVERAGE)
unsatisfied_count = survey_results.count(UNSATISFIED)
# 找出出现最多的意见数目
most_common_opinion_count = max(very_satisfied_count, satisfied_count, average_count, unsatisfied_count)
# 输出结果
print(f"Very Satisfied: {very_satisfied_count}")
print(f"Satisfied: {satisfied_count}")
print(f"Average: {average_count}")
print(f"Unsatisfied: {unsatisfied_count}")
print(f"Most common opinion count: {most_common_opinion_count}")
```
希望这个简单的代码能够帮助到您。
阅读全文