Solution- End Term Paper Python Programming
Solution- End Term Paper Python Programming
Q2. “Universe” is a base class having a sub class called “Planet”. Class “Universe” has private
member called “atmosphere” and a protected member “mass” (Initialize both variables with
custom values). Design a suitable class for the given scenario and discuss how private and
protected members can be inherited in the sub class or accessed outside the base class.
Specify appropriate reasons in case any of the member cannot be inherited or is inaccessible
outside the class.
class Universe:
def __init__(self):
self._mass="Solid"
self.__atmosphere="Nitro"
print(self.__atmosphere)
class Planet(Universe):
def __init__(self):
Universe.__init__(self)
print(self._mass)
obj1=Universe()
obj2=Planet()
Nitro
Nitro
Solid
True
False
True
1
Q4. Discuss the significance of “Self Parameter” in the methods of a class with the help of a
suitable example.
a) Write an appropriate code to create the dictionary for the above entity and display the
output for the same.
(3 marks)
nirf_ranking={"Institute": "Amity University", "Place": "Mohali",
"No_of_Courses":10, "Lab_structure":{"Architecture_labs":3,
"Computer_labs":9, "Science_labs":4}}
print(nirf_ranking)
b) Illustrate how to get a list of keys, values, and items independently using dictionary
methods from the above dictionary (Also specify the output).
x=nirf_ranking.keys()
y=nirf_ranking.values()
z=nirf_ranking.items()
print(x)
print(y)
print(z)