0% found this document useful (0 votes)
6 views5 pages

12cs Revision Sunday Test 2 Ans 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)
6 views5 pages

12cs Revision Sunday Test 2 Ans 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/ 5

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

5 What will be the output of following program: str="PYTHON4CSIP" 2


VEDIC VIDYASHRAM SENIOR SECONDARY SCHOOL for i in range(len(str)):
TIRUNELVELI-627 358 if(str[i].isdigit()):
(Academic Year : 24-25)
print(str[i],end='')
Grade : XII COMPUTER SCIENCE (083) Marks : 100
if(str[i]=='N'or str[i]=='Y'):
Date : SPECIAL TEST-2 (Answer Key) Time : 3Hrs
print('#',end='')
QNo. Question Mark
Ans: ##4
1 What will be the output of following program: str1 = 'Hello' 2
6 (Any one) 3
str2 ='World!'
a) Write a Program to Calculate the Number of Words and the Number of
print('str1 + str2 = ', str1 + str2) print('str1 * 3 =', str1 * 3)
Characters Present in a String
Ans: str1 + str2 = HelloWorld! str1 * 3 = HelloHelloHello
b) Write a Program to Calculate the Number of Upper Case Letters and Lower Case
2 What will be the output of following program: 2
Letters in a String
s="python4csip" n = len(s)
c) Write a Program to Form a New String Made of the First 2 and Last 2
m=''
characters From a Given String
for i in range(0, n):
d) Write a Program to Count the Occurrences of Each Word in a Given String
if (s[i] >= 'a' and s[i] <= 'm'):
Sentence
m = m + s[i].upper()
7 What will be the output of following code- 2
elif (s[i] >= 'n' and s[i] <= 'z'):
a={}
m = m + s[i-1]
a[2]=1 a[1]=[2,3,4]
elif (s[i].isupper()):
print(a[1][1])
m = m + s[i].lower()
Ans: 3
else:
m = m + '#' 8 Predictthe Output: 2

print(m) dict1={"name":"Mike","salary":8000} temp = dict1.pop("age")

Ans: ppyHho#CcIi print(temp)


Ans: Key error
3 What will be the output of following program: str ='Hello Python' 2
print (str) print (str[0]) 9 Whatwillbetheoutputoffollowingprogram: a={} 2

print (str[2:8]) a['a']=1 a['b']=[2,3,4]

print (str[3:]) print (str * 3) print(a)


Ans: {'a':1,'b':[2,3,4]}
print (str + "String")
Ans: 10 What will be the output of following program: 2

Hello Python H a={1:"A",2:"B",3:"C"}

llo Py b=a.copy() b[2]="D"

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

for i in range(len(str)): if(str[i].isalpha()): box = {}

print(str[i-1],end='') jars = {} crates={}

if(str[i].isdigit()): box['biscuit']=1

print(str[i],end='') box['cake']=3

Ans: jars['jam'] = 4 crates['box'] = box crates['jars']=jars print(len([crates]))


1
2

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

print(list1 + list2) sampleList.pop()


Page
Page
print(sampleList) sampleList.pop(2) print(sampleList) 27 Write the output of the following : 3
Ans: T1 = (1, 2, 3, 4, 5, 6, 7, 8)
[10, 20, 30, 40] print(T1[1 : : 2])
[10, 20, 40] print(T1[-1 : -5 : -2])
21 What will be the output of following program: A = [2, 4, 6, 8,10] 2 print(T1[: : -1])
L = len (A) print(T1[ : 7 : 2])
S = 0 Ans.
for I in range (1, L, 2): (2, 4, 6, 8)
S+=A[I] (8, 6)
print("Sum=",S) (8, 7, 6, 5, 4, 3, 2, 1)
Ans: Sum= 12 (1, 3, 5, 7)
22 Given a Python list, find value 20 in the list, and if it is present, replace it with 200. 2 28 Consider the following tuple and write the code for the following statements : 3
Only update the first occurrence of a value list1 = [5, 10, 15, 20, 25, 50, 20] Expected T1 = (12, 3, 45, ‘Hockey’, ‘Anil’, (‘a’, ‘b’))
output: list1 = [5, 10, 15, 200, 25, 50, 20] a. Display the first element of ‘T1’
23 Write a Python program to count the number of strings where the string length is 2 or 2 b. Display the last element of ‘T1’
more and the first and last character are same from a given list of strings. c. Display ‘T1’ in reverse order.
Sample List : ['abc', 'xyz', 'cbc', '121'] Expected Result : 2 d. Display ‘Anil’ from tuple ‘T1’
24 What will be the output of the following program: 2 e. Display ‘b’ from tuple ‘T1’
l=[10,20,30,40,50,60] Ans.
for i in range(len(l)): a. print(T1[0])
if(i%2==0): b. print(T1[-1])
print(l[i],end='#') c. print(T1[: : -1])
else: d. print(T1[4]) or print(T1[-2])
print(l[i]) e. print(T1[-1][-1]) or print(T1[5][1])
25 What will be the output of the following program: l=[10,20,30,40,50,60] 2 29 Write the output of the following : 3
for i in range(len(l)): T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)
if(i%2==0): print(sorted(T1))
print(l[i],end='#') print(sorted(T1[2 : 7]))
else: print(T1.index(23))
print(l[i],end='@') print(T1.index(23, 3, 9))
26 Write the output of the following code : 2 Ans.
T1 = (1, 2, 3, 4, 5, 6, 7, 8) [2, 4, 5, 7, 9, 10, 12, 23, 23, 23, 32]
print(T1) [2, 4, 5, 12, 23]
print(T1 * 2) 0
print(T1 + T1) 6
print(len(T1) * 2) 30 Write a program to accept three numbers from the user and insert it at the end of 2
Ans. given Tuple T1.
(1, 2, 3, 4, 5, 6, 7, 8) T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)
(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8) 31 Write a program to remove a number (accepted from the user) from the given tuple T1 3
(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8) = (12, 15, 18, 21, 24, 27, 30)
5
6

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

TOTAL = float (T) + C


Page
Page

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy