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

Holiday worksheet class 12

Uploaded by

joshuajj2110
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)
32 views

Holiday worksheet class 12

Uploaded by

joshuajj2110
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

EBENEZER MARCUS INTERNATIONAL SCHOOL & JR.

COLLEGE
COMPUTER SCIENCE WORKSHEET
CLASS XII

1. Identify the output of the following code snippet:


text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)

2. Which of the following expressions evaluates to False?


(A) not(True) and False
(B) True or False
(C) not(False and True)
(D) True and not(False)

3. What is the output of the expression?


country='International'
print(country.split("n"))
(A) ('I', 'ter', 'atio', 'al')
(B) ['I', 'ter', 'atio', 'al']
(C) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
(D) Error

4. What will be the output of the following code?


tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,)
print(tuple1 == tuple2)
(A) True
(B) False
(C) tuple1
(D) Error

5. If my_dict is a dictionary as defined below, then which of the


followingstatements will raise an exception?
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
(A) my_dict.get('orange')
(B) print(my_dict['apple', 'banana'])
(C) my_dict['apple']=20
(D) print(str(my_dict))

6. What will be the output of the following code?


c = 10
def add():
global c
c=c+2
print(c,end='#')
add()
c=15
print(c,end='%')

(A) 12%15# (B) 15#12% (C) 12#15% (D) 12%15#

7. If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then


(Answer using builtin functions only)
(A)Write a statement to count the occurrences of 4 in L1.
(B) Write a statement to sort the elements of list L1 in ascending order.
(C)Write a statement to insert all the elements of L2 at the end of L1.
(D) Write a statement to reverse the elements of list L2.

8. (A)Write a Python function that displays all the words containing @cmail
from a text file "Emails.txt".

(B) Write a Python function that finds and displays all the words longer
than5 characters from a text file "Words.txt".

9. Predict the output of the following code:


d = {"apple": 15, "banana": 7, "cherry": 9}
str1 = ""
for key in d:
str1 = str1 + str(d[key]) + "@" + “\n”
str2 = str1[:-1]
print(str2)

10. Predict the output of the following code:


line=[4,9,12,6,20]
for i in line:
for j in range(1,i%5):
print(j,’#’,end=””)
print()

11. The code provided below is intended to swap the first and last elements of
a given tuple. However, there are syntax and logical errors in the code.
Rewrite it after removing all errors. Underline all the corrections made.

def swap_first_last(tup)
if len(tup) < 2:
return tup
new_tup = (tup[-1],) + tup[1:-1] + (tup[0])
return new_tup
result=swap_first_last(1,2,3,4)
print(“Swapped tuple:”, result)
12. What will be the output of the following Python code?
a=[10,23,56,[78,10]]
b=list(a)
a[3][0]+=17
print(b)

13. Consider STACK=[23,45,67,89,51]. Write the STACK content after each


operations:
1. STACK.pop( )
2. STACK.append(99)
3. STACK.append(87)
4. STACK.pop( )

14. What will be the output of following program:


sampleList = [10, 20, 30, 40, 50]
sampleList.pop()
print(sampleList)
sampleList.pop(2)
print(sampleList)

15. What will be the output of following program:


L1 = list()
L1.append([1, [2, 3], 4])
L1.extend([7, 8, 9])
print(L1[0][1][1] + L1[2])

16. What will be the output of following program:


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)
Assertion and Reasoning Questions:

17. Assertion (A): CSV (Comma Separated Values) is a file format for data
storage that looks like a text file.

Reason (R): The information is organized with one record on each line and
each field is separated by a comma.

(a) Both A and R are true and R is the correct explanation for A

(b) Both A and R are true and R is not the correct explanation for A

(c) A is True but R is False

(d) A is false but R is True

18. Assertion(A): Python overwrites an existing file or creates a non-existing


file when we open a file with ‘w’ mode.

Reason(R): a+ mode is used only for writing operations

(a) Both A and R are true and R is the correct explanation for A

(b) Both A and R are true and R is not the correct explanation for A

(c) A is True but R is False

(d) A is false but R is True

19. Assertion. A variable declared inside a function cannot be used outside


it.

Reason. A variable created inside a function has a function scope.

(a) Both A and R are true and R is the correct explanation for A

(b) Both A and R are true and R is not the correct explanation for A

(c) A is True but R is False

(d) A is false but R is True


20. Assertion. Non-default arguments cannot follow default arguments in a
function call.

Reason. A function call can have different types of arguments.

(a) Both A and R are true and R is the correct explanation for A

(b) Both A and R are true and R is not the correct explanation for A

(c) A is True but R is False

(d) A is false but R is True

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