College Details: A technical event was conducted by the Government of India for the various colleges from all over India. On the valedictory function, a momento was given to all the colleges with the college details inscribed on it. The momento’s order was given to a famous epigrapher who does it manually. But since many colleges had participated it was difficult for him to do it manually. So he requests the management team to arrage a software code which would display the college details so that it would be easy for him to put it in his machine. The management team asks the development team to write a code which display the college details (specified in the Input format). Imagine you are working in the development team and this work is assigned to you. Write a code as per the requirement.
Create a base class CollegeName with one variable:
Attribute | Data Type |
college_name | str |
Use __init__() method for initializing the attributes of the above class.
Create a base class Establishment with one variable:
Attribute | Data Type |
establishment | int |
Use __init__() method for initializing the attributes of the above class.
Create a Class Details with the following attributes which is derived from both CollegeName and Establishment
Attribute | Data Type |
num_of_department | int |
address | str |
Use __init__() method for initializing the attributes of the above class.
Override the str() method to display the details in the format shown in the output in the class.
Input and Output Format:
Input consists of college(str), Year of Establishment (int), Number of departments (int) and address( str).
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and rest correspond to output.
Sample Input and Output:
College Details
Enter the College name
GSSS
Year of Establishment
2003
Enter the number of departments
50
Enter the address
West Siang, Arunachal Pradesh
College name : GSSS
Year of Establishment : 2003
Number of departments : 50
Address : West Siang, Arunachal Pradesh
Additional Sample TestCases
Sample Input and Output 1 :
College Details Enter the College name GSSS Year of Establishment 2003 Enter the number of departments 50 Enter the address West Siang, Arunachal Pradesh College name : GSSS Year of Establishment : 2003 Number of departments : 50 Address : West Siang, Arunachal Pradesh
Solution
class CollegeName:
def __init__(self, college_name):
self.college_name = college_name
def __str__(self):
return "College name : " + self.college_name
class Establishment:
def __init__(self, establishment):
self.establishment = establishment
def __str__(self):
return "Year of Establishment : " + str(self.establishment)
class Details(CollegeName, Establishment):
def __init__(self, no_of_department, address):
self.no_of_department = no_of_department
self.address = address
def __str__(self):
return "Number of departments : " + str(self.no_of_department) + "\n" + "Address : " + self.address
print("College Details")
college_name = raw_input("Enter the College name\n")
establishment = int(raw_input("Year of Establishment\n"))
no_of_department = int(raw_input("Enter the number of departments"))
address = raw_input("Enter the address\n")
obj = CollegeName(college_name)
obj1 = Establishment(establishment)
obj2 = Details(no_of_department, address)
print(obj)
print(obj1)
print(obj2)
Happy Learning – If you require any further information, feel free to contact me.