0% found this document useful (0 votes)
50 views8 pages

12cs Revision Sunday Test 2 QP

Uploaded by

myappagreat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views8 pages

12cs Revision Sunday Test 2 QP

Uploaded by

myappagreat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

QCODE : 12CS-SPLT1-242502 R.No.

VEDIC VIDYASHRAM SENIOR SECONDARY SCHOOL


TIRUNELVELI-627 358
(Academic Year : 24-25)
Grade : XII COMPUTER SCIENCE (083) Marks : 100
Date : SPECIAL TEST-2 Time : 3Hrs
QNo. Question Mark
1 What will be the output of following program: str1 = 'Hello' 2
str2 ='World!'
print('str1 + str2 = ', str1 + str2) print('str1 * 3 =', str1 * 3)
2 What will be the output of following program: 2
s="python4csip" n = len(s)
m=''
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m + s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '#'
print(m)
3 What will be the output of following program: str ='Hello Python' 2
print (str) print (str[0])
print (str[2:8])
print (str[3:]) print (str * 3)
print (str + "String")
4 What will be the output of following program: str="Python4csip.com" 2
for i in range(len(str)): if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print(str[i],end='')
5 What will be the output of following program: str="PYTHON4CSIP" 2
for i in range(len(str)):
if(str[i].isdigit()):
print(str[i],end='')
if(str[i]=='N'or str[i]=='Y'):
print('#',end='')
6 (Any one) 3
a) Write a Program to Calculate the Number of Words and the Number of
1
Page

Characters Present in a String


b) Write a Program to Calculate the Number of Upper Case Letters and Lower Case
Letters in a String
c) Write a Program to Form a New String Made of the First 2 and Last 2
characters From a Given String
d) Write a Program to Count the Occurrences of Each Word in a Given String
Sentence
7 What will be the output of following code- 2
a={}
a[2]=1 a[1]=[2,3,4]
print(a[1][1])
8 Predictthe Output: 2
dict1={"name":"Mike","salary":8000} temp = dict1.pop("age")
print(temp)
9 Whatwillbetheoutputoffollowingprogram: a={} 2
a['a']=1 a['b']=[2,3,4]
print(a)
10 What will be the output of following program: 2
a={1:"A",2:"B",3:"C"}
b=a.copy() b[2]="D"
print(a)
11 a) What will be the output of following program: 2
box = {}
jars = {} crates={}
box['biscuit']=1
box['cake']=3
jars['jam'] = 4 crates['box'] = box crates['jars']=jars print(len([crates]))
b) What twill be the output of following program:
rec={"Name":"Python","Age":"20","Addr":"NJ","Country":"USA"} id1 = id(rec)
del rec
rec={"Name":"Python","Age":"20","Addr":"NJ","Country":"USA"} id2 = id(rec)
print(id1==id2)
12 What will be the output of following program: 2
aList = [1,2,3,5,6,1,5,6,1]
fDict={}
for i in aList:
fDict[i]=aList.count(i)
print (fDict)
13 (Any one from a,b,c and d is compulsory) 2+2
a) Write a Python program to get the maximum and minimum value in a dictionary.
b) Writea Python program to check a dictionary is empty o rnot.
2

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

elif (s[i] >= 'n' and s[i] <= 'z'):


Page
m = m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '#'
print(m)
result('Cricket')
36 Find the output 3
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)
37 Raman has written a code to find its sum of digits of a given number passed as 2
parameter to function sumdigits(n). His code is having errors. Rewrite the correct code
and underline the corrections made.
def sumdigits(n):
d=0
for x in str(n):
d=d+x
return d
n=int(input(‘Enter any number‛))
s=sumdigits(n)
print(‚Sum of digits‛,s)
38 a) Given is a Python List declaration: 2
list= [10, 20, 30, 40, 50, 60, 70, 80]
print(list[ : : 2])
(b) Write the output of the code given below:
squares = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
print(squares.pop(4))
39 Predict the output of following code: 2
def fun(x):
x[0] = 5
return x
6

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

You might also like