0% found this document useful (0 votes)
3 views3 pages

Python Functions Test

This document is a unit test for Grade XII Computer Science focusing on Python programming. It includes multiple-choice questions, short answer questions, and coding tasks related to Python functions, variable scopes, and error correction. The test is divided into three sections with a total of 25 marks.

Uploaded by

lakshmipriyanv
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)
3 views3 pages

Python Functions Test

This document is a unit test for Grade XII Computer Science focusing on Python programming. It includes multiple-choice questions, short answer questions, and coding tasks related to Python functions, variable scopes, and error correction. The test is divided into three sections with a total of 25 marks.

Uploaded by

lakshmipriyanv
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

LAKSHYA INTERNATIONAL SCHOOL

UNIT TEST – 1

Subject: Computer Science (Python)

Grade: XII

Max Marks: 25

SECTION – A (5 × 1 = 5 Marks)
1. What will be the output of the following code?

def fun(a, b=5, c=10):


return a + b + c

print(fun(2, c=3))

a) 10 b) 15 c) 5 d) Error

2. Which of the following correctly explains the LEGB rule?

a) Local → External → Global → Built-in


b) Local → Enclosing → Global → Built-in
c) Local → Global → Enclosing → Built-in
d) Built-in → Global → Enclosing → Local

3. Identify the type of variable used below:

x = 10
def test():
print(x)

a) Local b) Global c) Enclosing d) Constant

4. Which of the following is a valid function definition?

a) def func(a, b=2, c)


b) def func(a=1, b=2, c=3)
c) def func(a=1, b, c=3)
d) def func(a=1, b=2, c)
5. What will be the output?

def outer():
x=5
def inner():
print(x)
inner()

outer()

a) Error b) 0 c) 5 d) None

SECTION – B (6 × 2 = 12 Marks)
1. A) Explain the LEGB rule with a simple example.
B) What is the difference between local scope and enclosing scope?

2. Explain mutable and immutable function arguments with examples.

3. Identify and correct the errors:

def calculate(a=5, b):


print(a + b)

calculate(b=10, 5)

4. Write the output:

x = 20
def test():
x = 10
print(x)

test()
print(x)

5. Write the output:

def func(x, y=2):


return x * y

print(func(3))
print(func(3, 4))
6. What will be the output?

def outer():
x = 'Python'
def inner():
nonlocal x
x = 'Java'
inner()
print(x)

outer()

SECTION – C (2 × 3 = 6 Marks)
1. Write a Python function countTypes(L) that takes a list and returns count of even and odd
numbers.
Example: Input: [2,3,4,5,6] Output: {'Even':3, 'Odd':2}

2. Write a function scopeDemo() to demonstrate LEGB rule using nested functions.

You might also like