0% found this document useful (0 votes)
9 views4 pages

Practice Worksheet Cs

This document is a practice worksheet for 12th-grade Computer Science students, containing multiple-choice questions and programming exercises related to Python. Topics include function return values, variable types, string methods, and dictionary manipulation. The worksheet also includes assertion-reasoning questions and coding tasks that require writing Python functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Practice Worksheet Cs

This document is a practice worksheet for 12th-grade Computer Science students, containing multiple-choice questions and programming exercises related to Python. Topics include function return values, variable types, string methods, and dictionary manipulation. The worksheet also includes assertion-reasoning questions and coding tasks that require writing Python functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practice worksheet

Subject – Computer Science

Class – 12th

Multiple Choice Questions

1-What is the default return value for a function that does not return any value explicitly

a) None
b) Int
c) Double
d) Null

2- Which of the function call can be used to invoke the below function definition

def test(a,b,c,d):

a) test(1,2,3,4)
b) test(a=1,2,3,4)
c) test(a=1,b=2,c=3,4)
d) test(a=1,b=2,c=3,d=4)

3- What is a variable defined outside all the function referred to as ?

a) static variable
b) global variable
c) local variable
d) an automatic variable

4-  What does the strip() method do in Python?

1. Removes elements from a list

2. Removes leading and trailing whitespace from a string

3. Converts a string to lowercase

4. Replaces characters in a string

5- What is the output of the following function call?

def sample(x=5):

return x * 2

print(sample())

1. 5
2. 10
3. Error
4. None

6-Assertion-Reasoning Question
Assertion (A): Python is a dynamically typed language.
Reason (R): In Python, a variable’s data type is explicitly declared before assigning a value.

Options:

1. Both A and R are True, and R is the correct explanation of A.


2. Both A and R are True, but R is not the correct explanation of A.
3. A is True, but R is False.
4. A is False, but R is True.

7-Write a Python program that creates a dictionary named places where the keys represent city IDs
and the values represent city names. The program should then display only those city names that
contain the letter "o" in them.

8-Guess the output of the code given below

def compute(A=50, B=25):

result = A * B

A, B = B, A

print("Result:", result, "Updated A:", A, "Updated B:", B)

return A

X = 10

Y=5

X = compute(X, Y)

print(X, "@", Y)

Y = compute(Y)

9-Write a Python program that takes two lists, L and M, of the same size and creates a new list, N,
where each element in N is the absolute difference between the corresponding elements in L and M.

L = [3, 1, 4]

M = [1, 5, 9]

Expected output:

N = [2, 4, 5]

10-Write a function word_stats(STRING) that takes a string as an argument and returns a


dictionary where:

 The keys are the unique words in the string.


 The values are the count of each word in the string.

Example Input:
sentence = "come let us have some fun let us enjoy"

output should be:

{'come': 1, 'let': 2, 'us': 2, 'have': 1, 'some': 1, 'fun': 1, 'enjoy': 1}

10-Write a user-defined function in Python named replace_vowels(w, n) that takes an English


word w and an integer n. The function should replace every n-th vowel in the word with an
underscore (_), leaving all other characters unchanged.

Example input

w = "TELEVISION"

n=2

output

TE_EVISI_N

11- Write a function LeftRotate(arr, n) in Python that accepts a list arr of numbers and an integer n.
The function should rotate the list to the left by n positions.

Input

arr = [10, 20, 30, 40, 50]

n=2

output

[30, 40, 50, 10, 20]

You might also like