Last active
May 12, 2021 12:12
-
-
Save TanjimReza/4a6c4804596201c251ddea742816b196 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CSEDepartment: | |
total_student = 0 | |
def __init__(self, name, credit): | |
self.name = name | |
self.credit = credit | |
def __str__(self): | |
s = "Program: " + self.name + ", Credit hours: "+ str(self.credit) | |
return s | |
class CSEProgram(CSEDepartment): | |
def __init__(self,name, credit): | |
super().__init__(name, credit) | |
print("CSE students need to complete " + str(self.credit) + " credits") | |
def addStudentWithCredits(self,*args): | |
self.names = [] | |
self.credits = [] | |
for i in range(0,len(args),2): | |
self.names.append(args[i]) | |
self.credits.append(args[i+1]) | |
CSEDepartment.total_student +=1 | |
def __str__(self): | |
s = super().__str__() + "\nTotal Student(s): " + str(len(self.names)) + "\nStudent details: \n" | |
for i in range(len(self.names)): | |
name = "Name: " + self.names[i] | |
credit = self.credits[i] | |
s += str(name) + ", Credit Remaining: " + str(credit) + "\n" | |
return s | |
class CSProgram(CSEDepartment): | |
def __init__(self,name, credit): | |
super().__init__(name, credit) | |
print("CS students need to complete " + str(self.credit) + " credits") | |
def addStudentWithCredits(self,*args): | |
self.names = [] | |
self.credits = [] | |
for i in range(0,len(args),2): | |
self.names.append(args[i]) | |
self.credits.append(args[i+1]) | |
CSEDepartment.total_student +=1 | |
def __str__(self): | |
s = super().__str__() + "\nTotal Student(s): " + str(len(self.names)) + "\nStudent details: \n" | |
for i in range(len(self.names)): | |
name = "Name: " + self.names[i] | |
credit = self.credits[i] | |
s += str(name) + ", Credit Remaining: " + str(credit) + "\n" | |
return s | |
p1 = CSEProgram("CSE", 136) | |
print("=================================") | |
p1.addStudentWithCredits("Bob", 12, "Carol", 18, "Mike", 15) | |
print("=================================") | |
print(p1) | |
print("=================================") | |
p2 = CSProgram("CS", 124) | |
print("=================================") | |
p2.addStudentWithCredits("David", 12, "Simon", 18) | |
print("=================================") | |
print(p2) | |
print("=================================") | |
print("Total Students in CSE Department: ", CSEDepartment.total_student) | |
""" | |
Output: | |
CSE students need to complete 136 credits | |
=============================== | |
=============================== | |
Program: CSE, Credit hours: 136 | |
Total students(s): 3 | |
Student details: | |
Name: Bob, Credit remaining: 124 | |
Name: Carol, Credit remaining: 118 | |
Name: Mike, Credit remaining: 121 | |
=============================== | |
CS students need to complete 124 credits | |
=============================== | |
=============================== | |
Program: CS, Credit hours: 124 | |
Total students(s): 2 | |
Student details: | |
Name: David, Credit remaining: 112 | |
Name: Simon, Credit remaining: 106 | |
=============================== | |
Total Students in CSE Department: 5 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment