0% found this document useful (0 votes)
4 views

12cs Revision Sunday Test 2 Qp 1

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)
4 views

12cs Revision Sunday Test 2 Qp 1

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/ 4

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

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

m = m + s[i].upper() a['a']=1 a['b']=[2,3,4]

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

m = m + s[i-1] 10 What will be the output of following program: 2

elif (s[i].isupper()): a={1:"A",2:"B",3:"C"}

m = m + s[i].lower() b=a.copy() b[2]="D"

else: print(a)

m = m + '#' 11 a) What will be the output of following program: 2

print(m) box = {}

3 What will be the output of following program: str ='Hello Python' 2 jars = {} crates={}

print (str) print (str[0]) box['biscuit']=1

print (str[2:8]) box['cake']=3

print (str[3:]) print (str * 3) jars['jam'] = 4 crates['box'] = box crates['jars']=jars print(len([crates]))

print (str + "String") b) What twill be the output of following program:

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)

for i in range(len(str)): if(str[i].isalpha()): del rec

print(str[i-1],end='') rec={"Name":"Python","Age":"20","Addr":"NJ","Country":"USA"} id2 = id(rec)

if(str[i].isdigit()): print(id1==id2)

print(str[i],end='') 12 What will be the output of following program: 2

5 What will be the output of following program: str="PYTHON4CSIP" 2 aList = [1,2,3,5,6,1,5,6,1]

for i in range(len(str)): fDict={}

if(str[i].isdigit()): for i in aList:

print(str[i],end='') fDict[i]=aList.count(i)

if(str[i]=='N'or str[i]=='Y'): print (fDict)

print('#',end='') 13 (Any one from a,b,c and d is compulsory) 2+2

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

elif (s[i] >= 'n' and s[i] <= 'z'): g = [10,11,12]


Page
Page
print(fun(g),g) CNT = 3
test_list = [5, 6, 7] TOTAL = 0
test_tup = (9, 10) for C in [7,5,4,6]:
res = tuple(list(test_tup) + test_list) T = TXT[CNT]
print(str(res)) TOTAL = float (T) + C
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 *********
7
8

TXT = ["10","20","30","5"]
Page
Page

You might also like