1:题目
通信技术、电子信息技术和自动化技术的发展与交叉融合极大地促进了社会发展,便利了人们的生活,学生成绩管理系统的出现和普及就是一个典型的例子。尝试编写程序,模拟学生成绩管理系统的功能。
后台管理员只有一个账户,用户名:admin,密码:password。
系统中学生的5门主干课成绩存在score.txt文件中,每行为一个学生的信息,分别记录了学生的学号、姓名以及5门课成绩,格式如下:
1820161002 Minhao 68 66 83 77 56
1820161129 Hongwei 91 70 81 91 96
现在某班学生需要评选学金,请按要求完成以下两个需求:
(1) 管理员进行登录,分别输入用户名和密码,若用户名或密码错误,则提示“Wrong username or password!”,并返回再次输入,总共有三次机会,若超过输入错误超过三次,则提示“It’s been more than three chances to log in!”;
(2) 管理员登录成功后,可以进行奖学金候选人筛选,过程如下:
1) 打印出按总成绩从高到低排序的学生名单,每行显示一个学生的信息,分别为学生学号、姓名以及5门课成绩。
2) 奖学金候选人的条件是: (a)总成绩排名在前6名; (b)全部课程及格(成绩大于等于60)。从上述名单中选出候选人,并打印,格式如下:
1820161129 Hongwei
1820161002 Minhao
【输入形式】 admin
password
【输出形式】
依序输出:
1.
分别提示输入用户名"username: "和密码"password: ",输入正确,提示“success!”,输入错误,提示“Wrong username or password!”,超过三次,提示“It’s been more than three chances to log in!”,并退出程序
2.
3.
登录成功后,提示“Start of scholarship selection!”
4.
5.
打印出按总成绩从高到低排序的学生名单,每行显示一个学生的信息,分别为学生学号、姓名以及5门课成绩
6.
7.
根据奖学金候选人条件进行筛选,提示“The candidates for the scholarships are as follows:”,并打印候选人信息
8.
【样例输入1】 admin
password
【样例输出2】username: password: success!
Start of scholarship selection!
sorted:
1820161129 Hongwei 91 70 81 91 96
1820161002 Minhao 68 66 83 77 56
……
The candidates for the scholarships are as follows:
1820161129 Hongwei (以空格为间隔)
1820161002 Minhao
……
【样例输入2】ad ef
【样例输出2】Wrong username or password!
Please try again.
【样例说明】 样例仅是展示,非测试数据
【评分标准】
2:代码
def login():
"""
分别提示输入用户名"username: "和密码"password: ",输入正确,
提示“success!”,输入错误,提示“Wrong username or password!”,
超过三次,提示“It's been more than three chances to log in!”,
并退出程序
"""
flag=False
term=0
name="admin"
password="password"
while flag==False and term <3:
if term==1 or term==2:
print("Please try again.")
in_name=input()
in_pass=input()
if in_name==name and in_pass==password:
print("username: password: success!")
return True
else:
if term !=2:
print("username: password: Wrong username or password!")
term=term+1
print("username: password: Wrong username or password!")
print("Please try again.")
print("It's been more than three chances to log in!",end="")
return False
def open_list():
ls_st=[]
f=open("score.txt","r")
for l in f:
info=l.split(" ")
if "\n" in info:
info.remove('\n')
sum=0
for i in range(2,7):
sum=sum+eval(info[i])
# info[-1]=str(eval(info[-1]))
info.append(sum)
ls_st.append(info)
def sort_fun(x1):
return x1[-1]
ls_st.sort(key=sort_fun,reverse=True)
# for i in ls_st:
# print(i)
f.close()
return ls_st
def print_score_list(ls_st):
"""
打印出按总成绩从高到低排序的学生名单,
每行显示一个学生的信息,
分别为学生学号、姓名以及5门课成绩。
"""
for i in ls_st:
ls=[]
ls.clear()
i=i[:-1]
for j in i:
ls.append(str(j))
s=" ".join(ls)
print(s)
def scholor_list(ls_st):
"""
奖学金候选人的条件是:
(a)总成绩排名在前6名;
(b)全部课程及格(成绩大于等于60)。
"""
mon_ls=ls_st[:6] #筛选 总成绩排名在前6名;
ls_final=[]
for line in mon_ls: #筛选
flag=True
for j in range(2,7):
if eval(line[j])<60: #全部课程及格(成绩大于等于60)。
flag=False
if flag==True:
ls_final.append(line)
for i in ls_final:
print("{} {}".format(i[0],i[1]))
def main():
if login()==False:
return 0
else:
print("Start of scholarship selection!")
ls_st=open_list()
print("sorted: ")
print_score_list(ls_st)
print("The candidates for the scholarships are as follows:")
scholor_list(ls_st)
if __name__=="__main__":
main()
3:测试输出
admin
password
username: password: success!
Start of scholarship selection!
sorted:
1820161049 Wentao 91 88 86 87 95
1820161044 Hongwei 91 70 81 91 96
1820161048 Huangzi 91 88 76 85 68
1820161046 Liming 81 88 71 77 87
1820161051 Xiaojia 91 60 67 75 88
1820161052 Mingming 91 64 68 76 69
1820161047 Caicai 61 78 76 87 58
1820161043 Minhao 68 66 83 77 56
1820161045 Zhangwei 71 78 61 81 56
1820161050 Hongfang 71 80 66 57 65
The candidates for the scholarships are as follows:
1820161049 Wentao
1820161044 Hongwei
1820161048 Huangzi
1820161046 Liming
1820161051 Xiaojia
1820161052 Mingming
4:测试数据
1820161049 Wentao 91 88 86 87 95
1820161044 Hongwei 91 70 81 91 9776
1820161048 Huangzi 91 88 776 85 68
1820161046 Liming 81 88 71 77 87
1820161051 Xiaojia 91 60 67 75 88
1820161052 Mingming 17 64 68 76 69
1820161047 Caicai 61 78 76 87 58
1820161043 Minhao 68 66 83 77 56
1820161045 Zhangwei 71 78 61 851 56
1820161050 Hongfang 71 80 66 57 65
username: password: success!
Start of scholarship selection!
sorted:
1820161049 Wentao 91 88 86 87 95
1820161044 Hongwei 91 70 81 91 96
1820161048 Huangzi 91 88 76 85 68
1820161046 Liming 81 88 71 77 87
1820161051 Xiaojia 91 60 67 75 88
1820161052 Mingming 91 64 68 76 69
1820161047 Caicai 61 78 76 87 58
1820161043 Minhao 68 66 83 77 56
1820161045 Zhangwei 71 78 61 81 56
1820161050 Hongfang 71 80 66 57 65
The candidates for the scholarships are as follows:
1820161049 Wentao
1820161044 Hongwei
1820161048 Huangzi
1820161046 Liming
1820161051 Xiaojia
1820161052 Mingming