学生成绩 python_Python程序计算学生成绩 淩亂°似流年 2023-03-05 12:43 3阅读 0赞 学生成绩 python Given students details, marks in 5 subjects and we have to find student's grade. 给学生详细信息,在5门科目中打分,我们必须找到学生的成绩。 In this program, we are taking student name, roll number and marks in 5 subjects and **calculating student's grade** based on the percentage and printing the all details. 在此程序中,我们将在5个科目中获取学生的姓名,卷号和分数,并根据百分比**计算学生的成绩**并打印所有详细信息。 ## 使用Python代码查找学生成绩 **(**Python code to find student grade**)** ## # Python code to find student grade class Student: def __init__(self): self.__roll=0 self.__name="" self.__marks=[] self.__total=0 self.__per=0 self.__grade="" self.__result="" def setStudent(self): self.__roll=int(input("Enter Roll: ")) self.__name=input("Enter Name: ") print("Enter marks of 5 subjects: ") for i in range(5): self.__marks.append(int(input("Subject "+str(i+1)+": "))) def calculateTotal(self): for x in self.__marks: self.__total+=x def calculatePercentage(self): self.__per=self.__total/5 def calculateGrade(self): if self.__per>=85: self.__grade="S" elif self.__per>=75: self.__grade="A" elif self.__per>=65: self.__grade="B" elif self.__per>=55: self.__grade="C" elif self.__per>=50: self.__grade="D" else: self.__grade="F" def calculateResult(self): count=0 for x in self.__marks: if x>=50: count+=1 if count==5: self.__result="PASS" elif count>=3: self.__result="COMP." else: self.__result="FAIL" def showStudent(self): self.calculateTotal() self.calculatePercentage() self.calculateGrade() self.calculateResult() print(self.__roll,"\t\t",self.__name,"\t\t",self.__total,"\t\t",self.__per,"\t\t",self.__grade,"\t\t",self.__result) def main(): #Student object s=Student() s.setStudent() s.showStudent() if __name__=="__main__": main() **Output** **输出量** Enter Roll: 101 Enter Name: Prem Sharma Enter marks of 5 subjects: Subject 1: 22 Subject 2: 33 Subject 3: 55 Subject 4: 66 Subject 5: 77 101 Prem Sharma 253 50.6 D COMP. > 翻译自: [https://www.includehelp.com/python/calculate-student-grade.aspx][https_www.includehelp.com_python_calculate-student-grade.aspx] 学生成绩 python [https_www.includehelp.com_python_calculate-student-grade.aspx]: https://www.includehelp.com/python/calculate-student-grade.aspx
还没有评论,来说两句吧...