列表

详情


NP97. 班级管理

描述

牛牛的Python老师为了更好地管理班级,利用一个类Student来管理学生,这个类包含了学生姓名(str)、学号(str)、分数(int)、每次作业等级(list[str])等信息。请你帮助牛牛的老师实现这样一个类,并定义构造方法实现初始化,定义打印函数实现打印学生的姓名、学号、分数、提交作业的次数、每次作业的等级。

输入描述

第一行输入字符串表示学生姓名。
第二行输入字符串表示学生学号。
第三行输入整数表示学生得分。
第四行输入多个大写字母表示每次作业等级,用空格间隔。

输出描述

用一句话输出学生的姓名、学号、分数、提交作业的次数、每次作业的等级,可以参考输出样例。

示例1

输入:

NiuNiu
12345
90
A B C

输出:

NiuNiu's student number is 12345, and his grade is 90. He submitted 3 assignments, each with a grade of A B C

原站题解

Python 解法, 执行用时: 13ms, 内存消耗: 2944KB, 提交时间: 2022-07-22

class Student:
    def __init__(self,name,no,num,list):
        self.num = num
        self.name = name
        self.no = no 
        self.list = list
name = raw_input()
no = raw_input()
num = raw_input()
s = raw_input()
list = s.split()
workNumber = len(list)
d = Student(name, no, num, list)
print "{}'s student number is {}, and his grade is {}. He submitted {} assignments, each with a grade of {}".format(d.name,d.no,d.num,workNumber,s,)

Python 解法, 执行用时: 13ms, 内存消耗: 3120KB, 提交时间: 2022-07-11

class Student:
    def __init__(self,name,no,num,list):
        self.num = num
        self.name = name
        self.no = no
        self.list = list
name = raw_input()
no = raw_input()
num = raw_input()
s = raw_input()
list = s.split()
workNumber = len(list)
d = Student(name, no, num, list)
print "{}'s student number is {}, and his grade is {}. He submitted {} assignments, each with a grade of {}".format(d.name,d.no,d.num,workNumber,s,)

Python 解法, 执行用时: 14ms, 内存消耗: 2948KB, 提交时间: 2022-06-11

class Student(object):
    def __init__(self, name, sid, score, rank):
        self.name = name
        self.id = sid
        self.score = score
        self.a = rank
        self.alen = len(rank.split(" "))
name = raw_input()
sid = int(raw_input())
score = int(raw_input())
a = raw_input()
d = Student(name, sid, score, a)
print(d.name+"'s student number is "+str(d.id)+", and his grade is "+str(d.score)+". He submitted "+str(d.alen)+" assignments, each with a grade of "+d.a)

Python 3 解法, 执行用时: 30ms, 内存消耗: 4472KB, 提交时间: 2022-07-19

class Student:
    def __init__(self,name,number,grade,homework):
        self.name = name
        self.number = number
        self.grade = grade
        self.homework = homework
 
stu = Student
name =input()
number=input()
grade = input()
homework =input()
print(f"{name}'s student number is {number}, and his grade is {grade}. He submitted {len(homework.split(' '))} assignments, each with a grade of {homework}")

Python 3 解法, 执行用时: 30ms, 内存消耗: 4492KB, 提交时间: 2022-07-15

a = input()
b = input()
c = input()
d = input()
g = 0
x = d
name = a + "'s student number is " + b + ', '
point = 'and his grade is ' + c + '. '
for i in x.replace(' ',''):
    g += 1
sor = 'He submitted '+ str(g) + ' assignments, each with a grade of ' + d
print(name + point + sor)

上一题