In [51]: #ANSWER 1(A)
#Roll no. DS5B-2028
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
n=int(input("Enter last digit of roll no. "))
print(factorial(n))
Enter last digit of roll no. 8
40320
In [55]: #Answer 1 (B)
# Birthday date is 13.12, so here taking 1312 and 3121
num=[]
for i in range(1312, 3121):
if (i%7==0) and (1%5!=0):
num.append(str(i))
print(','. join(num))
1316,1323,1330,1337,1344,1351,1358,1365,1372,1379,1386,1393,1400,1407,1
414,1421,1428,1435,1442,1449,1456,1463,1470,1477,1484,1491,1498,1505,15
12,1519,1526,1533,1540,1547,1554,1561,1568,1575,1582,1589,1596,1603,161
0,1617,1624,1631,1638,1645,1652,1659,1666,1673,1680,1687,1694,1701,170
8,1715,1722,1729,1736,1743,1750,1757,1764,1771,1778,1785,1792,1799,180
6,1813,1820,1827,1834,1841,1848,1855,1862,1869,1876,1883,1890,1897,190
4,1911,1918,1925,1932,1939,1946,1953,1960,1967,1974,1981,1988,1995,200
2,2009,2016,2023,2030,2037,2044,2051,2058,2065,2072,2079,2086,2093,210
0,2107,2114,2121,2128,2135,2142,2149,2156,2163,2170,2177,2184,2191,219
8,2205,2212,2219,2226,2233,2240,2247,2254,2261,2268,2275,2282,2289,229
6,2303,2310,2317,2324,2331,2338,2345,2352,2359,2366,2373,2380,2387,239
4,2401,2408,2415,2422,2429,2436,2443,2450,2457,2464,2471,2478,2485,249
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
2,2499,2506,2513,2520,2527,2534,2541,2548,2555,2562,2569,2576,2583,259
0,2597,2604,2611,2618,2625,2632,2639,2646,2653,2660,2667,2674,2681,268
8,2695,2702,2709,2716,2723,2730,2737,2744,2751,2758,2765,2772,2779,278
6,2793,2800,2807,2814,2821,2828,2835,2842,2849,2856,2863,2870,2877,288
4,2891,2898,2905,2912,2919,2926,2933,2940,2947,2954,2961,2968,2975,298
2,2989,2996,3003,3010,3017,3024,3031,3038,3045,3052,3059,3066,3073,308
0,3087,3094,3101,3108,3115
In [49]: #ANSWER 2 (A)
val=int(input("Press 1 for areaCircle,2 for circumferenceCircle,3 for a
reaSquare,4 for perimeterSquare"))
if val==1:
def areaCircle(r):
return (3.14*r*r)
print('Area of Circle is ',areaCircle(4))
elif val==2:
def cicumCircle(r):
return((2*3.14*r))
print('Cicumference of Circle is ',circumCircle(4))
elif val==3:
def areaSquare(a):
return(a*a)
print('Area of Square is ',areaSquare(4))
else:
def perSquare(a):
return (4*a)
print('Perimeter of Square is ',periSquare(4))
Press 1 for areaCircle,2 for circumferenceCircle,3 for areaSquare,4 for
perimeterSquare3
Area of Square is 16
In [46]: #ANSWER 2(B)
dict1=dict()
roll_num=int(input("Enter the last number of your roll number"))
for i in range(1,5+1):
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
dict1[i]=i*i
print(dict1)
Enter the last number of your roll number8
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
In [3]: # ANSWER 3 (A)i
import numpy as np
array1= np.array([80,70,80,60,50,75,88,90,35,79,100,95,85,75,65,66,65,8
0,94,91])
print(array1)
[ 80 70 80 60 50 75 88 90 35 79 100 95 85 75 65 66 65 8
0
94 91]
In [9]: array1[1:5]
Out[9]: array([70, 80, 60, 50])
In [10]: array1.ndim
Out[10]: 1
In [11]: np.append(array1,100)
Out[11]: array([ 80, 70, 80, 60, 50, 75, 88, 90, 35, 79, 100, 95, 85,
75, 65, 66, 65, 80, 94, 91, 100])
In [12]: np.insert(array1,5,100)
Out[12]: array([ 80, 70, 80, 60, 50, 100, 75, 88, 90, 35, 79, 100, 95,
85, 75, 65, 66, 65, 80, 94, 91])
In [13]: np.delete(array1,4)
Out[13]: array([ 80, 70, 80, 60, 75, 88, 90, 35, 79, 100, 95, 85, 75,
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
65, 66, 65, 80, 94, 91])
In [16]: array1.sort()
print(array1)
[ 35 50 60 65 65 66 70 75 75 79 80 80 80 85 88 90 91 9
4
95 100]
In [18]: #ANSWER 3 (A)ii
multi_array=np.array([[1,2,3,4],[5,6,7,8],[15,16,17,18],[25,26,27,28]])
print(multi_array)
[[ 1 2 3 4]
[ 5 6 7 8]
[15 16 17 18]
[25 26 27 28]]
In [19]: multi_array.transpose()
Out[19]: array([[ 1, 5, 15, 25],
[ 2, 6, 16, 26],
[ 3, 7, 17, 27],
[ 4, 8, 18, 28]])
In [20]: numpy.diagonal(multi_array)
Out[20]: array([ 1, 6, 17, 28])
In [21]: multi_array.shape
Out[21]: (4, 4)
In [22]: np.random.rand(4,5)
Out[22]: array([[0.66262097, 0.10036303, 0.37324788, 0.69861716, 0.30847342],
[0.73419248, 0.6803475 , 0.82289498, 0.40045986, 0.75673831],
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
[0.96041816, 0.76179807, 0.24483973, 0.24427745, 0.89085102],
[0.23436003, 0.69970021, 0.49276341, 0.63298998, 0.32312401]])
In [26]: #ANSWER 3 (B)
#FOR LIST
emplist=["Harry","Rohan","Riya"]
print(emplist)
['Harry', 'Rohan', 'Riya']
In [27]: print(emplist[1])
Rohan
In [28]: print(emplist[1:])
['Rohan', 'Riya']
In [29]: emplist[1]="Shreyans"
print(emplist)
['Harry', 'Shreyans', 'Riya']
In [30]: emplist[1:2]=["Shreyansh","Ana"]
print(emplist)
['Harry', 'Shreyansh', 'Ana', 'Riya']
In [31]: emplist.append("Sunita")
print(emplist)
['Harry', 'Shreyansh', 'Ana', 'Riya', 'Sunita']
In [32]: emplist.insert(1,"Sam")
print(emplist)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
['Harry', 'Sam', 'Shreyansh', 'Ana', 'Riya', 'Sunita']
In [33]: # FOR TUPLE
emptuple=("Harry","Sam","Sunita")
print(emptuple)
('Harry', 'Sam', 'Sunita')
In [34]: print(emptuple[-1])
Sunita
In [36]: # TUPLES CANNOT BE UPDATED
emptuple.append("Shreyans")
print(emptuple)
-----------------------------------------------------------------------
----
AttributeError Traceback (most recent call l
ast)
<ipython-input-36-e64053f518fb> in <module>
----> 1 emptuple.append("Shreyans")
2 print(emptuple)
AttributeError: 'tuple' object has no attribute 'append'
In [39]: #FOR DICTIONARY
empdict={"Harry":"Management","Sam":"Admin","Shreyans":"Developer"}
In [44]: x=empdict.get("Shreyans")
print(x)
Developer
In [45]: empdict.update({"Sunita":"Admin"})
print(empdict)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
{'Harry': 'Management', 'Sam': 'Admin', 'Shreyans': 'Developer', 'Sunit
a': 'Admin'}
In [24]: # ANSWER 5 (A)
#Roll no. DS5B-2028
#class India
class India:
def indplace(self):
print("Taj Mahal is a famous place in India")
#class Bangladesh
class Bangladesh:
def banplace(self):
print("Lal Bagh Fort is a famous place in Bangladesh")
#class Asia - Multiple inheritance to d
class Asia(India,Bangladesh):
def dispplace(self):
print("Asian Places")
In [25]: asian_place=Asia()
#Displaying Asian Famous Places
asian_place.dispplace()
asian_place.indplace()
asian_place.banplace()
Asian Places
Taj Mahal is a famous place in India
Lal Bagh Fort is a famous place in Bangladesh
In [56]: #ANSWER 6 (A)
#Roll no. DS5B-2028
custTrans = [100,800,400,200,600]
disc_10=[]
disc_5 = []
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
for i in custTrans:
if i>=500:
temp= (i*10)/100
disc_10.append(i)
else:
temp1=(i*5)/100
disc_5.append(i)
print(disc_10)
print(disc_5)
disc_val=disc_10+disc_5
print('Total Discount Value: ',disc_val)
def sum(num):
total = 0
for x in num:
total += x
return total
print('Total Discount Value in Rs.: ',sum(disc_val))
[800, 600]
[100, 400, 200]
Total Discount Value: [800, 600, 100, 400, 200]
Total Discount Value in Rs.: 2100
In [60]: # ANSWER 7 (B)
class Student:
def __init__(self, name, rollno, m1, m2):
self.name = name
self.rollno = rollno
self.m1= m1
self.m2 = m2
In [62]: def display(self, ob):
print("Name : ", ob.name)
print("RollNo : ", ob.rollno)
print("Marks1 : ", ob.m1)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
print("Marks2 : ", ob.m2)
print("\n")
def search(self, rn):
for i in range(ls._len_()):
if(ls[i].rollno == rn):
return i
ls =[]
obj = Student('', 0, 0, 0)
print("\nOperations used, ")
print("1.Display Student Details\n""2.Search Details of a Student\n")
ch = int(input("Enter choice:"))
if(ch == 1):
#print("\n")
print("List of Students")
for i in range(ls._len_()):
obj.display(ls[i])
else:
print(" Student Found, ")
s = obj.search(2)
obj.display(ls[s])
Operations used,
1.Display Student Details
2.Search Details of a Student
Enter choice:2
Student Found,
-----------------------------------------------------------------------
----
AttributeError Traceback (most recent call l
ast)
<ipython-input-62-94ab35c6a229> in <module>
24 else:
25 print(" Student Found, ")
---> 26 s = obj.search(2)
27 obj.display(ls[s])
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
AttributeError: 'Student' object has no attribute 'search'
In [ ]:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD