Advertisement
Arcot

ch11 ex3

Apr 6th, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. class Student():
  2.     def __init__(self, name, age, list_of_marks):
  3.         self.name = name
  4.         self.age = age
  5.         self.marks = {
  6.             "english" : list_of_marks[0],
  7.             "science" : list_of_marks[1],
  8.             "maths" : list_of_marks[2]
  9.         }
  10.  
  11.     def get_all_subjects(self):
  12.         return list(self.marks.keys())
  13.  
  14.     def check_subject(self, subject):
  15.         return subject in self.marks.keys()
  16.  
  17.         #if subject in self.marks.keys():
  18.         #    return True
  19.         #else:
  20.         #    return False
  21.    
  22.     def getAverage(self):
  23.         return sum(self.marks.values())/len(self.marks.values())
  24.  
  25. batch = []
  26.  
  27. for i in range(3):
  28.     name = input("Enter name of student: ")
  29.     age = input("Enter age of student: ")
  30.     list_of_marks = input("Enter list of marks(seprated by ','): ").split(",")
  31.     stu = Student(name, age, list_of_marks)
  32.     batch.append(stu)
  33.  
  34. for stu in batch:
  35.     print(stu.name,"has",stu.marks["maths"],"marks in maths")
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement