Functions: Class 12 PYQs 2024–2026 with solutions
All 16 CBSE board questions asked from Functions in 3 board papers, with the year, set and marks of each. 10 are solved free below. The Class 12 Computer Science PYQ Book: Solved Board Papers 2024-2026 (CBSE) has every solution, all chapters and 3 full board papers.
Functions: board weightage
Board weightage 2024–2026
| Year | 2024 | 2025 | 2026 |
|---|---|---|---|
| Questions | 6 | 5 | 5 |
| Marks | 9 | 10 | 10 |
Most asked topics
16 questions from 3 papers. Repeated questions are shown once with every year they were asked.
1 mark: MCQ and Assertion–Reason
def f1(a,b=1): / print(a+b,end='-') / c=f1(1,2) / print(c,sep='*') (A) 3-2 (B) 3-2* (C) 3-None (D) 3*None-
Solution
(C) 3-None. f1 prints 1+2 = 3 followed by '-'. f1 has no return, so c = None; printing a single value ignores sep.
def Change(N): / N=N+10 / print(N,end='$$') / N=15 / Change(N) / print(N) (A) 25$$15 (B) 15$$25 (C) 25$$25 (D) 2525$$
Solution
(A) 25$$15. Inside, the local N becomes 25 and is printed with end '$$'; the global N stays 15.
True or False: While defining a function, the positional parameters in the header must always be written after the default parameters.
Solution
False. It is the reverse: default parameters must come after positional parameters; def f(a=1, b) is a SyntaxError.
Possible output? import random / Signal=['RED','YELLOW','GREEN'] / for K in range(2,0,-1): / R=random.randrange(K) / print(Signal[R],end='#') (a) YELLOW#RED# (b) RED#GREEN# (c) GREEN#RED# (d) YELLOW#GREEN#
a=20 / def convert(a): / b=20; a=a+b / convert(10) / print(a) (a) 10 (b) 20 (c) 30 (d) Error
2 marks: very short answer
Difference between default parameters and positional parameters; give a header that uses both.
Solution
Default parameters have a value in the header that is used if no argument is passed; positional parameters get their values from the arguments according to their position. In a header, default parameters come after positional ones: def Q22(X, Y=10): (X positional, Y default).
Which output(s) will NOT be displayed? How many times does the loop run? a=[1,2,3,4,5,6] / for i in range(4): / j=random.randrange(i,5) / print(a[j],end='-') (A) 3-4-5-4- (B) 2-2-4-5- (C) 4-3-3-5- (D) 5-1-2-4-
Solution
j ranges: i=0 → 0–4 (values 1–5); i=1 → 1–4 (2–5); i=2 → 2–4 (3–5); i=3 → 3–4 (4–5). In (D) the second value 1 is impossible (minimum is 2). (A), (B), (C) fit. Answer: (D) 5-1-2-4- will not be displayed; the loop runs 4 times.
Rewrite after removing errors (count vowels): def CountVowels(s): / c=0 / for ch in range(s): / if 'aeiouAEIOU' in ch: / c=+1 / return(ch)
Solution
def CountVowels(s):
c = 0
for ch in s: # not range(s)
if ch in 'aeiouAEIOU': # operands swapped
c += 1 # += not =+
return c # return the count
c=+1 is legal but sets c to +1 each time (a logical error).What does the return statement do in a function? Explain with an example.
Solution
return exits the function and sends a value back to the statement that called it. def Add(A, B): return A + B; Result = Add(5, 3); print(Result) → 8. Without return the function gives None.
Possible output? Cards=["Heart","Spade","Club","Diamond"] / for i in range(2): / print(Cards[random.randint(1,i+2)],end="#") (A) Spade#Diamond# (B) Spade#Heart# (C) Diamond#Club# (D) Heart#Spade#
Solution
i = 0: randint(1, 2) → index 1 or 2 → Spade or Club. i = 1: randint(1, 3) → Spade, Club or Diamond. Heart (index 0) can never appear; Diamond cannot come first. Only (A) Spade#Diamond# is possible.
Rewrite after removing errors: def Sum(N) / for I in range(N): / S=S+I / return S / print(Sum(10) (sum of integers 1 to N)
Rewrite after removing syntax and logical errors (underline corrections): def EvenOdd() / for i in range(5): / num=int(input("Enter a number") / if num/2==0: / print("Even") / else: / print("Odd") / EvenOdd()
(A) Write showGrades(S); S has Name:[Eng,Math,Science]; display grade: average ≥ 90 → A, ≥ 60 → B, else C. E.g. S={"AMIT":[92,86,64],"NAGMA":[65,42,43],"DAVID":[92,90,88]} → AMIT - B, NAGMA - C, DAVID - A. OR (B) Puzzle(W,N): replace every Nth letter of W with "_" (TELEVISION, 3 → TE_EV_SI_N).
Predict the output: def callon(b=20,a=10): / b=b+a; a=b-a / print(b,"#",a); return b / x=100; y=200 / x=callon(x,y); print(x,"@",y) / y=callon(y); print(x,"@",y)
3 marks: short answer
(a) Output: def Exam2026(given): / new=[] / for ch in given[1:-1]: / if ch.isupper(): new.reverse() / elif ch not in new: new.append(ch) / elif ch in new: new.pop() / print(new) / Exam2026("Gold-24Medals")
OR (b) OR: def Exam2026(given): / new=0 / while given: / if new%2: new+=given%10 / else: new+=given%5 / print(new,end='-') / given//=10 / Exam2026(123456)
Solution
given[1:-1] = "old-24Medal". o → ['o']; l → ['o','l']; d → ['o','l','d']; - → [...,'-']; 2 → [...,'2']; 4 → ['o','l','d','-','2','4']; M (upper) → reverse → ['4','2','-','d','l','o']; e → append 'e'; d (present) → pop removes the last item 'e'; a → append 'a'; l (present) → pop removes 'a'.
['4', '2', '-', 'd', 'l', 'o']
OR given 123456: new 0 even → +6%5=1 → 1. 12345: new odd → +5 → 6. 1234: even → +4%5=4 → 10. 123: even → +3 → 13. 12: odd → +2 → 15. 1: odd → +1 → 16.
1-6-10-13-15-16-
(a) Predict the output: def ExamOn(mystr): / newstr=""; count=0 / for i in mystr: / if count%2!=0: newstr=newstr+str(count-1) / else: newstr=newstr+i.lower() / count+=1 / newstr=newstr+mystr[:2] / print("The new string is:",newstr) / ExamOn("GenX")
OR (b) OR: def Change(X): / for K,V in X.items(): / L1.append(K); L2.append(V) / D={1:"ONE",2:"TWO",3:"THREE"}; L1=[]; L2=[] / Change(D); print(L1); print(L2); print(D)
Solution
| i | count | action | newstr |
|---|---|---|---|
| G | 0 | even → 'g' | g |
| e | 1 | odd → str(0) | g0 |
| n | 2 | even → 'n' | g0n |
| X | 3 | odd → str(2) | g0n2 |
The new string is: g0n2Ge
OR L1 and L2 are global lists changed in place by append (no global keyword needed for that).
[1, 2, 3]
['ONE', 'TWO', 'THREE']
{1: 'ONE', 2: 'TWO', 3: 'THREE'}
Get every solution for all chapters
- Every board question of every chapter, each fully solved the way the board gives marks
- 3 complete board papers, each followed by its solutions
- Weightage and most-asked topics for every chapter
- Instant PDF download, colour and black & white print copies
Revising the chapter first? Complete Computer Science Notes for Class 12 (CBSE 083, 2026-27) →
What you get in the pack
- CBSE Class 12 Computer Science board papers 2024 to 2026 (3 full board papers)
- All 14 chapters and 3 board papers complete
- Part A: all 14 chapters, questions sorted chapter-wise and by marks
- Year-wise weightage table and most-asked topics for every chapter
- Part B: each full board paper followed by its complete solutions
- Full programs; every output traced and verified by running the code
- Only the current syllabus in Part A
All chapters in this pack
- PYQ Ch 1 Python Revision Tour
- PYQ Ch 2 Functions
- PYQ Ch 3 Exception Handling
- PYQ Ch 4 Text Files
- PYQ Ch 5 Binary Files
- PYQ Ch 6 CSV Files
- PYQ Ch 7 Stack
- PYQ Ch 8 Computer Networks I: Evolution and Data Communication
- PYQ Ch 9 Computer Networks II: Devices, Topologies and Types
- PYQ Ch 10 Network Protocols and Web Services
- PYQ Ch 11 Database Concepts
- PYQ Ch 12 SQL: DDL, DML and Queries
- PYQ Ch 13 SQL: Aggregates, Grouping and Joins
- PYQ Ch 14 Interface of Python with MySQL
- Board Paper 2026 Set 91 with Solutions
- Board Paper 2025 Set 91 with Solutions
- Board Paper 2024 Set 91 with Solutions
