12cs Revision Sunday Test 2 Ans 1
12cs Revision Sunday Test 2 Ans 1
lo Python print(a)
Hello PythonHello PythonHello Python Hello PythonString Ans: {1:'A',2: 'B',3: 'C'}
4 What will be the output of following program: str="Python4csip.com" 2 11 a) What will be the output of following program: 2
if(str[i].isdigit()): box['biscuit']=1
print(str[i],end='') box['cake']=3
mPytho44csi.co Ans: 1
Page
Page
b) What twill be the output of following program: Ans:
rec={"Name":"Python","Age":"20","Addr":"NJ","Country":"USA"} id1 = id(rec) ['python', 'list', 1952, 2323, 432]
del rec ['list', 1952, 2323]
rec={"Name":"Python","Age":"20","Addr":"NJ","Country":"USA"} id2 = id(rec) ['list', 1952, 2323, 432]
print(id1==id2) python
Ans: False ['python', 'list', 1952, 2323, 432, 'python', 'list', 1952, 2323, 432]
12 What will be the output of following program: 2 ['python', 'list', 1952, 2323, 432, 'this', 'is', 'another', 'list']
aList = [1,2,3,5,6,1,5,6,1] 16 What will be the output of following program: l=[6,12,18,24,30] 2
fDict={} for i in l:
for i in aList: for j in range(1,i%5):
fDict[i]=aList.count(i) print(j,'#',end='')
print (fDict) print()
Ans: {1:3, 2: 1,3: 1, 5:2, 6: 2} Ans:
13 (Any one from a,b,c and d is compulsory) 2+2 1 #
a) Write a Python program to get the maximum and minimum value in a dictionary. 1 #2 #
b) Writea Python program to check a dictionary is empty o rnot. 1 #2 #3 #
c) Python Program to Create a Dictionary with Key as First Character and Value as 17 What will be the output of following program: 2
Words Starting with that Character. myList = [1, 5, 5, 5, 5, 1]
d) Write a Python script to concatenate following dictionaries to create a newone max = myList[0] indexOfMax = 0
.dic1= {1:10,2:20} for i in range(1, len(myList)):
dic2= {3:30,4:40} if myList[i] > max:
dic3= {5:50,6:60} max = myList[i] indexOfMax = i
Ans: print(indexOfMax)
dic={} Ans: 1
dic1= {1:10,2:20} 18 What will be the output of following program: 2
dic2={3:30,4:40} values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]
dic3= {5:50,6:60} for row in values: row.sort()
14 What will be the output of following program: 2 for element in row:
>>>a=[2,1,3,5,2,4] print(element, end = " ")
>>>a.remove(2) print()
>>>a Ans:
Ans: [1, 3, 5, 2, 4] 1 3 4 5
15 What will be the output of following program: 2 1 2 6 33
list1 = ["python", "list", 1952, 2323, 432] 19 What will be the output of following program: 2
list2 = ["this", "is", "another", "list"] a="hello"
print(list1) b=list((x.upper(),len(x))
print(list1[1:4]) for x in a:
print(list1[1:]) print(b)
print(list1[0]) Ans: [('H', 1), ('E', 1), ('L', 1), ('L', 1), ('O', 1)]
print(list1 * 2) 20 What will be the output of following program: sampleList = [10, 20, 30, 40, 50] 2
3
4
16 SAMPLE EXECUTION
Page
Page
Enter element to remove : 21 print(m)
Tuple after removing element is : (12, 15, 18, 24, 27, 30) result('Cricket')
Ans. 36 Find the output 3
T1 = (12, 15, 18, 21, 24, 27, 30) Msg1="WeLcOME"
el = int(input("Enter the element to be removed : ")) Msg2="GUeSTs"
if el in T1: Msg3=""
L = list(T1) for I in range(0,len(Msg2)+1):
L.remove(el) if Msg1[I]>="A" and Msg1[I]<="M":
T1 = tuple(L) Msg3=Msg3+Msg1[I]
print(T1) elif Msg1[I]>="N" and Msg1[I]<="Z":
else: Msg3=Msg3+Msg2[I]
print("Element not found") else:
OUTPUT : Msg3=Msg3+"*"
Enter the element to be removed : 21 print(Msg3)
(12, 15, 18, 24, 27, 30) 37 Raman has written a code to find its sum of digits of a given number passed as 2
32 mylist = [2,14,54,22,17] 2 parameter to function sumdigits(n). His code is having errors. Rewrite the correct code
tup = tuple(mylist) and underline the corrections made.
for i in tup: def sumdigits(n):
print(i%3, end=",") d=0
33 Predict the output of the following code: 2 for x in str(n):
def CALLME(n1=1,n2=2): d=d+x
n1=n1*n2 return d
n2+=2 n=int(input(‘Enter any number”))
print(n1,n2) s=sumdigits(n)
CALLME() print(“Sum of digits”,s)
CALLME(3) 38 a) Given is a Python List declaration: 2
34 Python funtion oddeve(L) to print positive numbers in a list L. 2 list= [10, 20, 30, 40, 50, 60, 70, 80]
Example: Input: [4, -1, 5, 9, -6, 2, -9, 8] Output: [4, 5, 9, 2, 8] print(list[ : : 2])
35 Write the output of following python code: 3 (b) Write the output of the code given below:
def result(s): squares = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
n = len(s) print(squares.pop(4))
m='' 39 Predict the output of following code: 2
for i in range(0, n): def fun(x):
if (s[i] >= 'a' and s[i] <= 'm'): x[0] = 5
m = m + s[i].upper() return x
elif (s[i] >= 'n' and s[i] <= 'z'): g = [10,11,12]
m = m + s[i-1] print(fun(g),g)
elif (s[i].isupper()): test_list = [5, 6, 7]
m = m + s[i].lower() test_tup = (9, 10)
else: res = tuple(list(test_tup) + test_list)
7
8
m = m + '#' print(str(res))
Page
Page
40 Write a function listchange(Arr,n)in Python, which accepts a list Arr of numbers and n is 3 print (TOTAL)
an numeric value depicting length of the list. Modify the list so that all even numbers CNT-=1
doubled and odd number multiply by 3 Sample Input Data of the list: (OR)
Arr= [ 10,20,30,40,12,11], n=6 Output: Arr = [20,40,60,80,24,33] def check(x,y):
41 Write output of the following code: 2 if x != Y:
value = 50 return x + 5
def display(N): else:
global value return y +10
value = 25 print(check(10,5))
if N%7==0: 45 What possible output(s) are expected to be displayed on screen at the time of execution 2
value = value + N of the program from the following code? Also write the value assigned to variable first
else: and second.
value = value - N from random import randint
print(value, end="#") LST=[5,10,15,20,25,30,35,40,45,50,60,70]
display(20) first = random.randint(3,8) – 1
print(value) second = random.randint(4,9) – 2
42 Aman has write the code to find factorial of an integer number as follow. But he got 2 third = random.randint(6,11) – 3
some error while running this program. Kindly help him to correct the errors. print(LST[first],"#", LST[second],"#", LST[third],"#")
num=int(input("Enter any integer number")) i) 20#25#25#
fact=1 ii) 30#40#70#
for x of range(num,1,-1): iii) 15#60#70#
if num=1 or num=0 iv) 35#40#60#
print ("Fact=1") 46 Predict the output: 3
break def func(S):
else k=len(S); m=''
fact=fact*x for i in range(0,k):
print(fact) if S[i].isalpha( ):
43 a) Given a list: 2 m=m+S[i].upper( )
List1=[10,[20,30,40],50,60,70,80,90] elif S[i].isdigit( ):
What will be the output of m=m+'0'
print(List1[1:3:2])? else:
b) Write the output of following code: m=m+'#'
Tup1=(10,15,20,25,30) print(m)
print(Tup1[-1:0:-2]) func("Python 3.9")
44 Write the output of the following Python program code: 2 *********
TXT = ["10","20","30","5"]
CNT = 3
TOTAL = 0
for C in [7,5,4,6]:
T = TXT[CNT]
9
10