12cs Revision Sunday Test 2 QP
12cs Revision Sunday Test 2 QP
c) Python Program to Create a Dictionary with Key as First Character and Value as
Page
Words Starting with that Character.
d) Write a Python script to concatenate following dictionaries to create a newone
.dic1= {1:10,2:20}
dic2= {3:30,4:40}
dic3= {5:50,6:60}
14 What will be the output of following program: 2
>>>a=[2,1,3,5,2,4]
>>>a.remove(2)
>>>a
15 What will be the output of following program: 2
list1 = ["python", "list", 1952, 2323, 432]
list2 = ["this", "is", "another", "list"]
print(list1)
print(list1[1:4])
print(list1[1:])
print(list1[0])
print(list1 * 2)
print(list1 + list2)
16 What will be the output of following program: l=[6,12,18,24,30] 2
for i in l:
for j in range(1,i%5):
print(j,'#',end='')
print()
17 What will be the output of following program: 2
myList = [1, 5, 5, 5, 5, 1]
max = myList[0] indexOfMax = 0
for i in range(1, len(myList)):
if myList[i] > max:
max = myList[i] indexOfMax = i
print(indexOfMax)
18 What will be the output of following program: 2
values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]
for row in values: row.sort()
for element in row:
print(element, end = " ")
print()
19 What will be the output of following program: 2
a="hello"
b=list((x.upper(),len(x))
for x in a:
3
print(b)
Page
20 What will be the output of following program: sampleList = [10, 20, 30, 40, 50] 2
sampleList.pop()
print(sampleList) sampleList.pop(2) print(sampleList)
21 What will be the output of following program: A = [2, 4, 6, 8,10] 2
L = len (A)
S = 0
for I in range (1, L, 2):
S+=A[I]
print("Sum=",S)
22 Given a Python list, find value 20 in the list, and if it is present, replace it with 200. 2
Only update the first occurrence of a value list1 = [5, 10, 15, 20, 25, 50, 20] Expected
output: list1 = [5, 10, 15, 200, 25, 50, 20]
23 Write a Python program to count the number of strings where the string length is 2 or 2
more and the first and last character are same from a given list of strings.
Sample List : ['abc', 'xyz', 'cbc', '121'] Expected Result : 2
24 What will be the output of the following program: 2
l=[10,20,30,40,50,60]
for i in range(len(l)):
if(i%2==0):
print(l[i],end='#')
else:
print(l[i])
25 What will be the output of the following program: l=[10,20,30,40,50,60] 2
for i in range(len(l)):
if(i%2==0):
print(l[i],end='#')
else:
print(l[i],end='@')
26 Write the output of the following code : 2
T1 = (1, 2, 3, 4, 5, 6, 7, 8)
print(T1)
print(T1 * 2)
print(T1 + T1)
print(len(T1) * 2)
27 Write the output of the following : 3
T1 = (1, 2, 3, 4, 5, 6, 7, 8)
print(T1[1 : : 2])
print(T1[-1 : -5 : -2])
print(T1[: : -1])
print(T1[ : 7 : 2])
4
28 Consider the following tuple and write the code for the following statements : 3
Page
T1 = (12, 3, 45, ‘Hockey’, ‘Anil’, (‘a’, ‘b’))
a. Display the first element of ‘T1’
b. Display the last element of ‘T1’
c. Display ‘T1’ in reverse order.
d. Display ‘Anil’ from tuple ‘T1’
e. Display ‘b’ from tuple ‘T1’
29 Write the output of the following : 3
T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)
print(sorted(T1))
print(sorted(T1[2 : 7]))
print(T1.index(23))
print(T1.index(23, 3, 9))
30 Write a program to accept three numbers from the user and insert it at the end of 2
given Tuple T1.
T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)
31 Write a program to remove a number (accepted from the user) from the given tuple T1 3
= (12, 15, 18, 21, 24, 27, 30)
SAMPLE EXECUTION
Enter element to remove : 21
Tuple after removing element is : (12, 15, 18, 24, 27, 30)
32 mylist = [2,14,54,22,17] 2
tup = tuple(mylist)
for i in tup:
print(i%3, end=",")
33 Predict the output of the following code: 2
def CALLME(n1=1,n2=2):
n1=n1*n2
n2+=2
print(n1,n2)
CALLME()
CALLME(3)
34 Python funtion oddeve(L) to print positive numbers in a list L. 2
Example: Input: [4, -1, 5, 9, -6, 2, -9, 8] Output: [4, 5, 9, 2, 8]
35 Write the output of following python code: 3
def result(s):
n = len(s)
m=''
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m + s[i].upper()
5
g = [10,11,12]
Page
print(fun(g),g)
test_list = [5, 6, 7]
test_tup = (9, 10)
res = tuple(list(test_tup) + test_list)
print(str(res))
40 Write a function listchange(Arr,n)in Python, which accepts a list Arr of numbers and n is 3
an numeric value depicting length of the list. Modify the list so that all even numbers
doubled and odd number multiply by 3 Sample Input Data of the list:
Arr= [ 10,20,30,40,12,11], n=6 Output: Arr = [20,40,60,80,24,33]
41 Write output of the following code: 2
value = 50
def display(N):
global value
value = 25
if N%7==0:
value = value + N
else:
value = value - N
print(value, end="#")
display(20)
print(value)
42 Aman has write the code to find factorial of an integer number as follow. But he got 2
some error while running this program. Kindly help him to correct the errors.
num=int(input("Enter any integer number"))
fact=1
for x of range(num,1,-1):
if num=1 or num=0
print ("Fact=1")
break
else
fact=fact*x
print(fact)
43 a) Given a list: 2
List1=[10,[20,30,40],50,60,70,80,90]
What will be the output of
print(List1[1:3:2])?
b) Write the output of following code:
Tup1=(10,15,20,25,30)
print(Tup1[-1:0:-2])
44 Write the output of the following Python program code: 2
7
TXT = ["10","20","30","5"]
Page
CNT = 3
TOTAL = 0
for C in [7,5,4,6]:
T = TXT[CNT]
TOTAL = float (T) + C
print (TOTAL)
CNT-=1
(OR)
def check(x,y):
if x != Y:
return x + 5
else:
return y +10
print(check(10,5))
45 What possible output(s) are expected to be displayed on screen at the time of execution 2
of the program from the following code? Also write the value assigned to variable first
and second.
from random import randint
LST=[5,10,15,20,25,30,35,40,45,50,60,70]
first = random.randint(3,8) – 1
second = random.randint(4,9) – 2
third = random.randint(6,11) – 3
print(LST[first],"#", LST[second],"#", LST[third],"#")
i) 20#25#25#
ii) 30#40#70#
iii) 15#60#70#
iv) 35#40#60#
46 Predict the output: 3
def func(S):
k=len(S); m=''
for i in range(0,k):
if S[i].isalpha( ):
m=m+S[i].upper( )
elif S[i].isdigit( ):
m=m+'0'
else:
m=m+'#'
print(m)
func("Python 3.9")
*********
8
Page