赞
踩
- import string
- n = int(input())
- dic = {}
- f = open("step2/The Old Man and the Sea.txt", "r")
-
- i = 0
- for line in f:
- if i>=n:
- break
- else:
- i+=1
- for word in line.lower():
- if word.isalpha():
- dic[word] = dic.get(word, 0)+1
-
- list = sorted(dic.items(), key=lambda x: (-x[1], x[0]))
- for x1,x2 in list:
- print("{} 的数量是 {:>3} 个".format(x1, x2))
- for c in string.ascii_lowercase:
- if c not in dic:
- print(f"{c} 的数量是 {0:>3} 个")
- with open('step3/The Great Learning.txt', 'r', encoding='utf-8') as f:
- n =int(input())
- text = ''.join(f.readlines()[:n])
- sum1 = len(text)
- sum2 = len(set(text))
- print(sum1, sum2)
- with open('step4/university.csv','r',encoding='utf-8') as Uname:
- ls = Uname.readlines()
- name = input()
- print(ls[0].strip())
- for i in ls:
- if name in i.split(','):
- print(i)
- break
- with open('step5/university.csv','r',encoding='utf-8') as Uname:
- ls = Uname.readlines()
- key = input()
- for i in ls:
- if key in i.split(',')[1]:
- print(i.split(',')[1])
-
-
-
- a = input()
- if a in 'AD':
- with open('step6//info.csv','r',encoding='utf-8') as f:
- if a=='A':
- print(f.read().replace(',',' '))
- elif a=='D':
- dic = {}
- ls = f.readlines()
- for i in ls:
- lst = i.strip().split(',')
- dic[lst[0]] = [lst[1],lst[2]]
- print(dic)
- else:
- print('ERROR')
-
-
- import json
-
- with open('step7/score1034.json', 'r', encoding='utf-8') as f:
- text = json.loads(f.read())
- ls = [['姓名', '学号', 'C', 'C++', 'Java', 'Python', 'C#', '总分']]
- for i in text:
- ls.append(list(i.values()))#获取字典中所有值
- n = int(input())
- print(ls[:n])
- with open('step8/成绩单.csv', 'r', encoding='utf-8') as f:
- n = int(input())
- ls = []
- av = [0,0,0,0,0,0]
- for line in f.readlines():
- ls.append(line.strip('\n').split(','))
- for j in range(3,9):
- av[j-3] = av[j-3]+int(line.split(',')[j])
- ls.sort(key = lambda x:int(x[9]))
- print('最低分{}分,最高分{}分'.format(ls[0][9], ls[-1][9]))
- print(ls[:n])#前n排数据
- if n <= len(ls):
- print(ls[(len(ls)-n):])#后n排数据
- else:
- print(ls)
- lst = []
- for j in range(0,6):
- lst.append(float(f'{int(av[j])/len(ls):.2f}'))
- print(lst)
-
-
- def one(filename):
- with open(filename, 'r') as f:
- ls = []
- for line in f.readlines()[1:]:
- res = line.strip().split(',')
- if eval(res[-1]) >= 0.8:
- ls.append(res)
- return ls
-
-
- def two(filename):
- with open(filename, 'r') as f:
- ls1 = []
- ls2 = []
- for line in f.readlines()[1:]:
- res = line.strip().split(',')
- if eval(res[-1]) >= 0.9:
- ls1.append(res)
- elif eval(res[-1]) <= 0.7:
- ls2.append(res)
- return ls1, ls2
-
-
- def main():
- n = input()
- filename = 'step9//admit2.csv'
- if n == '1':
- ls = one(filename)
- count = 0
- for i in ls:
- if eval(i[1]) >= 4:
- count += 1
- print('Top University in >=80%:{:.2f}%'.format(count / len(ls) * 100))
- elif n == 'Research':
- ls1, ls2 = two(filename)
- count = 0
-
- for i in ls1:
- if i[-4] == '1' :
- count+=1
- print('Research in >=90%:{:.2f}%'.format(count / len(ls1) * 100))
- count = 0
- for i in ls2:
- if i[-4] == '1' :
- count+=1
- print('Research in <=70%:{:.2f}%'.format(count / len(ls2) * 100))
- elif n == '2':
- ls = [eval(i[3]) for i in one(filename)]
- print('TOEFL Average Score:{:.2f}'.format(sum(ls) / len(ls)))
- print('TOEFL Max Score:{:.2f}'.format(max(ls)))
- print('TOEFL Min Score:{:.2f}'.format(min(ls)))
- elif n == '3':
- ls = [eval(i[4]) for i in one(filename)]
- print('CGPA Average Score:{:.3f}'.format(sum(ls) / len(ls)))
- print('CGPA Max Score:{:.3f}'.format(max(ls)))
- print('CGPA Min Score:{:.3f}'.format(min(ls)))
- else:
- print("ERROR")
-
-
- main()
-
-
-
-
-
- with open('step10/CBOOK.csv', 'r') as f:
- ls = [line.strip().split(',') for line in f.readlines()[1:]]
- n = input()
- if n == 'record':
- print(len(ls))
- elif n == 'rank':
- num = input()
- for i in ls:
- if i[0] == num:
- for j in i:
- print(j)
- elif n=='maxcomment':
- res = sorted(ls,key=lambda x:eval(x[5][:-3]),reverse = True)
- for i in res[:10]:
- print(i[1],i[5])
- elif n=='maxname':
- num =int(input())
- res = sorted(ls,key=lambda x:len(x[1]),reverse = True)
- for i in res[:num]:
- print(i[1])
- else:
- print('无数据')
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。