Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
General Instructions
i) All the questions are compulsory.
ii) Programming Language: Python.
iii) Database: MySQL
iii) Give appropriate examples wherever necessary.
ii. [1]
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print(len(numberGames) + sum)
print(numberGames)
iii. [½]
box = {}
jars = {}
crates = {}
box['biscuit'] = 1
box['cake'] = 3
jars['jam'] = 4
crates['box'] = box
crates['jars'] = jars
print(len(crates['box']))
iv. [½]
a=(1,2,3)
b=('A','B','C')
c= zip(a,b)
c= tuple(c)
print(c)
v. [½]
T = (1, 2, 3, 4, 5, 6, 7, 8)
print(T[T.index(5)], end = " ")
print(T[T[T[6]-3]-6])
vi. [1]
names1 = ['Amir', 'Bear', 'Charlton', 'Daman']
names2 = names1
names3 = names1[:]
names2[0] = "Alice"
names3[1] = "Bob"
sum = 0
for ls in (names1, names2, names3):
if ls[0] == "Alice":
sum += 1
if ls[1] == "Bob":
sum += 10
print(sum)
2. What will be stored in variables a, b,c ,d ,e and f after the following statements: [3]
T= (90, 98, 76, 45, 12, 11)
a = T[2:2]
b = T[2:]
c = T[:2]
d = T[:-2]
e = T[-2:]
f = T[2:-2]
3. Will this code give a runtime error of infinite loop or will it give the output 5, 6, 7, 8, 9?
Explain with the help of a dry run. [2]
x = 5
L = [5,6,7,8,9]
for i in range(0,x):
x= x+1
print(L[i])
4. What are the different ways in which you can add elements to a list? Give examples. [2]
5. What is the meaning of unpacking of tuples? Show example. What is the condition for
unpacking? [2]
6. Consider the following List of Characters. Assume that the bubble sort (in ascending order)
is being applied on the list. Show the different passes and the state of the list in each pass.
[2]
[‘f’,’z’,’e’,’w’,’b’]
7. What is the difference between del and pop in terms of a dictionary? What are the different
ways in which pop can be called for a dictionary? [2]
8. WAP to create a list of unique values of numbers from any given list. [3]
For example:
L= [1,1,3,8,3,0,7,4,5,2,0]
Newlist = [1,3,8,0,7,4,2]
Note: Use nested loops, do not use built in functions of list.
9. Use a list of tuples: [3]
((1,2),(3,4,5),(9,7,6,10))
Create a tuple with the means of the individual nested tuples.
i.e (1.5 , 4 , 8)
Find the mean of the final set of numbers in the tuple. In this case 4.5
(P.S: Mean of numbers is the average of the numbers.)
WAP to use the above lists to create a dictionary of names as key and the total of each
sublist as their corresponding total marks for example the resultant dictionary should be
Report = {“ajay”:333,”shreyas”:321……..}
Further iterate through the dictionary to print the results as:
Name: Total
Ajay 333
Shreyas 321
11. Write an algorithm to sort a list of numbers using insertion sort. [3]
12. What is the difference between Primary Key, Candidate Key and Alternate Key? Explain
with examples. [3]
13. Expand and give two commands examples for DDL and DML: [4]
a. DDL
b. DML
c. DTL
d. DCL
14. Consider the table below, write SQL for a-d and output for f-i. [8]
*********************************GOOD LUCK!*******************************