Home > other >  Python
Python

Time:05-22

Python
(1) design a StuGroup class, in this class include: a data member score (each student's score) and the two classes into
Member variable total (total) and count (number), setScore members method (socre) and getScore () is used to set and get scores,
Members method sum () is used for the total score, class methods business () used for averaging, interactive input this group of student achievement, according to the score of this group of students peace divide,
Note: refers to the instance attribute data members, members of the class refers to the class attribute, members of the methods refers to instance methods

CodePudding user response:

 
The class StuGroup () :

Total=0 # score
The count number=0 #

Def __init__ (self) :
Self. Score=[] # each student score

Def setScore (self) :
For s in the self. Score:
StuGroup. Total +=s
StuGroup. Count +=1

Def getScore (self) :
Score=input (" please enter the student scores, separated by Spaces: ')
Score=[float (n) for n in score. The split ()]
The self. The score=score

@ staticmethod
Def sum () :
Return StuGroup. Total

@ staticmethod
Def business () :
Return StuGroup. Total/StuGroup. Count


If __name__=="__main__ ':
S=StuGroup ()
S.g etScore ()
S.s etScore ()
Print (' student's score is: {} '. The format (StuGroup. The sum ()))
Print (' student's score is: {} '. The format (StuGroup. Business ()))


If works for you, please post for my score!