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

Class12 CS QuestionPaper Functions

This document is a question paper for Class 12 Computer Science covering Python topics such as functions and data types. It includes multiple sections with objective questions, short answers, application-based questions, and long answer questions, along with their solutions. The paper assesses students' understanding of Python programming concepts and their ability to write code.

Uploaded by

amandoyee2009
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)
0 views5 pages

Class12 CS QuestionPaper Functions

This document is a question paper for Class 12 Computer Science covering Python topics such as functions and data types. It includes multiple sections with objective questions, short answers, application-based questions, and long answer questions, along with their solutions. The paper assesses students' understanding of Python programming concepts and their ability to write code.

Uploaded by

amandoyee2009
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

Class 12 Computer Science

Question Paper and Solution - Python Revision Tour & Functions

Class 12 Computer Science - Chapter 1 & 2 Test

Max Marks: 35 Time: 1½ hours

Chapters Covered: Python Revision Tour & Functions

Section A: Objective (1 mark each) - [5 × 1 = 5 marks]

1. Which of the following is a valid identifier in Python?

a) 123abc b) _my_var c) def d) for

2. What is the output of:

print(type(3.0 + 4))

3. Which of the following is an immutable data type?

a) list b) set c) dict d) tuple

4. Which function returns the length of a string?

a) size() b) len() c) length() d) count()

5. A function defined inside another function is called:

a) Recursion b) Nested Function c) Lambda d) Built-in function

Section B: Short Answer (2 marks each) - [5 × 2 = 10 marks]

6. Differentiate between `is` and `==` in Python with an example.


7. What is the purpose of the `return` statement in a function?

8. Write a Python function to check if a number is even or odd.

9. Rewrite the following using while loop:

for i in range(1, 6):

print(i)

10. Write any two differences between global and local variables.

Section C: Application-Based Questions (3 marks each) - [4 × 3 = 12 marks]

11. Predict the output:

def test(a, b=3):

return a + b

print(test(2), test(2, 4))

12. Write a function `count_vowels(s)` that returns the number of vowels in a string.

13. What are default and keyword arguments? Give suitable code examples for each.

14. Write a Python program using recursion to find the sum of digits of a number.

Section D: Long Answer (4 marks each) - [2 × 4 = 8 marks]

15. Write a program to:

- Accept a list of numbers

- Define a function to return the second largest number

- Print the result

16. Write a recursive function to generate and print the Fibonacci series up to n terms.
Solutions

Solutions to Class 12 Computer Science - Python Revision Tour & Functions

Section A Answers:

1. b) _my_var

2. <class 'float'>

3. d) tuple

4. b) len()

5. b) Nested Function

Section B Answers:

6. `is` checks identity; `==` checks value.

Example:

a = [1, 2]; b = [1, 2]

a == b -> True; a is b -> False

7. `return` gives output from function to caller.

8. def check_even_odd(n):

if n % 2 == 0:

print("Even")

else:

print("Odd")

9. i = 1

while i <= 5:
print(i)

i += 1

10. Global: Declared outside, accessible everywhere

Local: Declared inside function

Section C Answers:

11. Output: 5 6

12. def count_vowels(s):

vowels = "aeiouAEIOU"

return sum(1 for ch in s if ch in vowels)

13. Default: def greet(name, msg="Hi")

Keyword: greet(name="Ravi", msg="Hello")

14. def sum_digits(n):

if n == 0: return 0

return (n % 10) + sum_digits(n // 10)

Section D Answers:

15. def second_largest(lst):

lst = list(set(lst))

lst.sort()

return lst[-2] if len(lst) >= 2 else None

nums = [4, 7, 2, 7, 1, 9]
print("Second Largest:", second_largest(nums))

16. def fib(n):

if n <= 1: return n

return fib(n-1) + fib(n-2)

for i in range(5):

print(fib(i), end=" ")

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