# 不允许修改。fopen函数打开文件,并返回包含文件数据一个列表ls,
def fopen(name):
ls = []
with open(name, 'r', encoding='UTF-8') as f:
for i in f.readlines()[1:]:
ls.append(i.strip().split(','))
return ls
def fun(s, ls): # 自定义函数完成相关功能,函数名或形参或函数数量可自行修改
if s == '程序员':
number = 0
for item in ls:
if item[1] == 'I am a developer by profession':
number += 1
print(f'程序员:{number}条')
elif s == '程序爱好者':
number = 0
for item in ls:
if item[1] == 'I code primarily as a hobby':
number += 1
print(f'程序爱好者:{number}条')
elif s == '程序初学者':
number = 0
for item in ls:
if item[1] == 'I am a student who is learning to code':
number += 1
print(f'程序初学者:{number}条')
elif s == '编程相关者':
number = 0
for item in ls:
if item[1] == '"I am not primarily a developer':
number += 1
print(f'编程相关者:{number}条')
elif s == '非程序员':
number = 0
for item in ls:
if item[1] == '"I used to be a developer by profession':
number += 1
print(f'非程序员:{number}条')
elif s == '空白':
number = 0
for item in ls:
if item[1] == 'NA':
number += 1
print(f'空白:{number}条')
elif s == '记录':
print(f'总计:{len(ls)}条')
else:
print('错误输入')
lt = fopen('survey.csv') # 不允许修改,打开题目文件,并将返回的数据列表赋值给lt
selection = input()
fun(selection, lt)
程序员问卷调查
最新推荐文章于 2023-10-24 08:43:20 发布