fileinfo = open('/home/wei/fty/test/im/fileFunction/studentInfo.log', 'r+',encoding = 'utf-8')
class maxinfo:
maxAge = 0
maxName = ''
count = 0
for lineInfo in fileinfo:
StudentInfo = lineInfo.strip('\n')
StudentTuple = StudentInfo.split(',')
name = StudentTuple[0]
sex = StudentTuple[1]
age = int(StudentTuple[2])
if age > maxinfo.maxAge:
maxinfo.maxAge = age
maxinfo.maxName = name
count += 1
print('年龄最大的是',maxinfo.maxName,',年龄是:',maxinfo.maxAge,'。','班级里总共有',count,'个学生。')
/*
studentInfo.log
张三,男,24
李四,女,22
王五,男,23
*/
统计班级的学生总数、学生最大的年龄以及姓名。
最新推荐文章于 2023-04-14 17:36:13 发布