12cs Revision Sunday Test 2 Qp 1
12cs Revision Sunday Test 2 Qp 1
b) Write a Program to Calculate the Number of Upper Case Letters and Lower Case
VEDIC VIDYASHRAM SENIOR SECONDARY SCHOOL Letters in a String
TIRUNELVELI-627 358 c) Write a Program to Form a New String Made of the First 2 and Last 2
(Academic Year : 24-25)
characters From a Given String
Grade : XII COMPUTER SCIENCE (083) Marks : 100
d) Write a Program to Count the Occurrences of Each Word in a Given String
Date : SPECIAL TEST-2 Time : 3Hrs
Sentence
QNo. Question Mark
7 What will be the output of following code- 2
1 What will be the output of following program: str1 = 'Hello' 2
a={}
str2 ='World!'
a[2]=1 a[1]=[2,3,4]
print('str1 + str2 = ', str1 + str2) print('str1 * 3 =', str1 * 3)
print(a[1][1])
2 What will be the output of following program: 2
8 Predictthe Output: 2
s="python4csip" n = len(s)
dict1={"name":"Mike","salary":8000} temp = dict1.pop("age")
m=''
print(temp)
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'): 9 Whatwillbetheoutputoffollowingprogram: a={} 2
else: print(a)
print(m) box = {}
3 What will be the output of following program: str ='Hello Python' 2 jars = {} crates={}
4 What will be the output of following program: str="Python4csip.com" 2 rec={"Name":"Python","Age":"20","Addr":"NJ","Country":"USA"} id1 = id(rec)
if(str[i].isdigit()): print(id1==id2)
print(str[i],end='') fDict[i]=aList.count(i)
6 (Any one) 3 a) Write a Python program to get the maximum and minimum value in a dictionary.
a) Write a Program to Calculate the Number of Words and the Number of b) Writea Python program to check a dictionary is empty o rnot.
1
2
Characters Present in a String c) Python Program to Create a Dictionary with Key as First Character and Value as
Page
Page
Words Starting with that Character. 20 What will be the output of following program: sampleList = [10, 20, 30, 40, 50] 2
d) Write a Python script to concatenate following dictionaries to create a newone sampleList.pop()
.dic1= {1:10,2:20} print(sampleList) sampleList.pop(2) print(sampleList)
dic2= {3:30,4:40} 21 What will be the output of following program: A = [2, 4, 6, 8,10] 2
dic3= {5:50,6:60} L = len (A)
14 What will be the output of following program: 2 S = 0
>>>a=[2,1,3,5,2,4] for I in range (1, L, 2):
>>>a.remove(2) S+=A[I]
>>>a print("Sum=",S)
15 What will be the output of following program: 2 22 Given a Python list, find value 20 in the list, and if it is present, replace it with 200. 2
list1 = ["python", "list", 1952, 2323, 432] Only update the first occurrence of a value list1 = [5, 10, 15, 20, 25, 50, 20] Expected
list2 = ["this", "is", "another", "list"] output: list1 = [5, 10, 15, 200, 25, 50, 20]
print(list1) 23 Write a Python program to count the number of strings where the string length is 2 or 2
print(list1[1:4]) more and the first and last character are same from a given list of strings.
print(list1[1:]) Sample List : ['abc', 'xyz', 'cbc', '121'] Expected Result : 2
print(list1[0]) 24 What will be the output of the following program: 2
print(list1 * 2) l=[10,20,30,40,50,60]
print(list1 + list2) for i in range(len(l)):
16 What will be the output of following program: l=[6,12,18,24,30] 2 if(i%2==0):
for i in l: print(l[i],end='#')
for j in range(1,i%5): else:
print(j,'#',end='') print(l[i])
print() 25 What will be the output of the following program: l=[10,20,30,40,50,60] 2
17 What will be the output of following program: 2 for i in range(len(l)):
myList = [1, 5, 5, 5, 5, 1] if(i%2==0):
max = myList[0] indexOfMax = 0 print(l[i],end='#')
for i in range(1, len(myList)): else:
if myList[i] > max: print(l[i],end='@')
max = myList[i] indexOfMax = i 26 Write the output of the following code : 2
print(indexOfMax) T1 = (1, 2, 3, 4, 5, 6, 7, 8)
18 What will be the output of following program: 2 print(T1)
values = [[3, 4, 5, 1 ], [33, 6, 1, 2]] print(T1 * 2)
for row in values: row.sort() print(T1 + T1)
for element in row: print(len(T1) * 2)
print(element, end = " ") 27 Write the output of the following : 3
print() T1 = (1, 2, 3, 4, 5, 6, 7, 8)
19 What will be the output of following program: 2 print(T1[1 : : 2])
a="hello" print(T1[-1 : -5 : -2])
b=list((x.upper(),len(x)) print(T1[: : -1])
for x in a: print(T1[ : 7 : 2])
3
4
print(b) 28 Consider the following tuple and write the code for the following statements : 3
Page
Page
T1 = (12, 3, 45, ‘Hockey’, ‘Anil’, (‘a’, ‘b’)) m = m + s[i-1]
a. Display the first element of ‘T1’ elif (s[i].isupper()):
b. Display the last element of ‘T1’ m = m + s[i].lower()
c. Display ‘T1’ in reverse order. else:
d. Display ‘Anil’ from tuple ‘T1’ m = m + '#'
e. Display ‘b’ from tuple ‘T1’ print(m)
29 Write the output of the following : 3 result('Cricket')
T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23) 36 Find the output 3
print(sorted(T1)) Msg1="WeLcOME"
print(sorted(T1[2 : 7])) Msg2="GUeSTs"
print(T1.index(23)) Msg3=""
print(T1.index(23, 3, 9)) for I in range(0,len(Msg2)+1):
30 Write a program to accept three numbers from the user and insert it at the end of 2 if Msg1[I]>="A" and Msg1[I]<="M":
given Tuple T1. Msg3=Msg3+Msg1[I]
T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23) elif Msg1[I]>="N" and Msg1[I]<="Z":
31 Write a program to remove a number (accepted from the user) from the given tuple T1 3 Msg3=Msg3+Msg2[I]
= (12, 15, 18, 21, 24, 27, 30) else:
SAMPLE EXECUTION Msg3=Msg3+"*"
Enter element to remove : 21 print(Msg3)
Tuple after removing element is : (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
5
6
TXT = ["10","20","30","5"]
Page
Page