0% found this document useful (0 votes)
42 views

Solution- End Term Paper Python Programming

Hey

Uploaded by

cvridhie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Solution- End Term Paper Python Programming

Hey

Uploaded by

cvridhie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Amity University Punjab, Mohali

BTech 3rd Semester (Nov 2023)


Mid Semester Test
CSE210: Python Programming

Total Marks: 25 Time = 50 mins

Note: All Questions are compulsory.

Section – A [4x4 =16 marks]

Q1. Given below two sets:


Car_type = {“sedan”, “SUV”, “hatchback”}
Car_model= {2021,2022,2022,2023,2020}
Describe various methods to join both the sets, also write the final output (Order may vary).

Car_type = {"sedan", "SUV", "hatchback"}


Car_model= {2021,2022,2023,2020,2022}
set3=Car_type.union(Car_model)
print(set3)
Car_type.update(Car_model)
print(Car_type)

{2023, 2020, 2021, 'sedan', 2022, 'SUV', 'hatchback'}


{2023, 2020, 2021, 'sedan', 2022, 'SUV', 'hatchback'}

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

Q3. Predict the output of the following statements:


x=(1==True)
y=(2==False)
z=(0==False)
t=1
print (x,"\n", y,"\n", z,"\n",t)

True
False
True
1

Q4. Discuss the significance of “Self Parameter” in the methods of a class with the help of a
suitable example.

Section – B [9x1 =9 marks]

Q1 Suppose there is an entity object “nirf_ranking” with following attributes:


Institute= Amity University, Place= Mohali, No_of_Courses=10,
Lab_structure={Architecture_labs=3, Computer_labs=9, Science_labs=4}

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)

{'Institute': 'Amity University', 'Place': 'Mohali', 'No_of_Courses': 1


0, 'Lab_structure': {'Architecture_labs': 3, 'Computer_labs': 9, 'Scien
ce_labs': 4}}

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)

dict_keys(['Institute', 'Place', 'No_of_Courses', 'Lab_structure'])


dict_values(['Amity University', 'Mohali', 10, {'Architecture_labs': 3,
'Computer_labs': 9, 'Science_labs': 4}])
dict_items([('Institute', 'Amity University'), ('Place', 'Mohali'), ('N
o_of_Courses', 10), ('Lab_structure', {'Architecture_labs': 3, 'Compute
r_labs': 9, 'Science_labs': 4})])
(3 marks)
c) Discuss various methods to remove the item “Lab_structure” from the given dictionary.
(3 marks)
nirf_ranking.pop("Lab_structure")
print(nirf_ranking)
nirf_ranking.popitem()
print(nirf_ranking)
del nirf_ranking["Lab_structure"]
print(nirf_ranking)
***END***

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy