Functions Class 12 PYQs 2024–2026 with Solutions | CBSE Computer Science Skip to content
Smart Notes for Every Exam · instant PDF download after payment +91 92520 37565
Class 12 · Computer Science · Chapter 2

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.

Cover of Class 12 Computer Science PYQ Book: Solved Board Papers 2024-2026 (CBSE)
Class 12 Computer Science PYQ book: every chapter + 3 board papers, all solved
US$1.99US$1.9934% off
Free sample

Functions: board weightage

Board weightage 2024–2026

Year202420252026
Questions655
Marks91010

Most asked topics

User-defined functions11
random module3
Parameters and arguments2

16 questions from 3 papers. Repeated questions are shown once with every year they were asked.

Jump to: 1 mark2 marks3 marks

1 mark: MCQ and Assertion–Reason

Q1 · CBSE 2026 · 91 · Q91 mark

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.

Q2 · CBSE 2025 · 91 · Q101 mark

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.

Q3 · CBSE 2024 · 91 · Q11 mark

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.

Q4 · CBSE 2024 · 91 · Q41 mark

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#

Full step-by-step solution is in the PYQ book (US$1.99).
Q5 · CBSE 2024 · 91 · Q121 mark

a=20 / def convert(a): /  b=20; a=a+b / convert(10) / print(a) (a) 10 (b) 20 (c) 30 (d) Error

Full step-by-step solution is in the PYQ book (US$1.99).

2 marks: very short answer

Q6 · CBSE 2026 · 91 · Q222 marks

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).

Q7 · CBSE 2026 · 91 · Q252 marks

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.

Q8 · CBSE 2026 · 91 · Q262 marks

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).

Q9 · CBSE 2025 · 91 · Q222 marks

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.

Q10 · CBSE 2025 · 91 · Q252 marks

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.

Q11 · CBSE 2025 · 91 · Q262 marks

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)

Full step-by-step solution is in the PYQ book (US$1.99).
Q12 · CBSE 2024 · 91 · Q202 marks

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()

Full step-by-step solution is in the PYQ book (US$1.99).
Q13 · CBSE 2024 · 91 · Q212 marks

(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).

Full step-by-step solution is in the PYQ book (US$1.99).
Q14 · CBSE 2024 · 91 · Q252 marks

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)

Full step-by-step solution is in the PYQ book (US$1.99).

3 marks: short answer

Q15 · CBSE 2026 · 91 · Q313 marks

(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-

Q16 · CBSE 2025 · 91 · Q313 marks

(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
icountactionnewstr
G0even → 'g'g
e1odd → str(0)g0
n2even → 'n'g0n
X3odd → str(2)g0n2
Then mystr[:2] = "Ge" is added.
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
See real pages (free sample)

Revising the chapter first? Complete Computer Science Notes for Class 12 (CBSE 083, 2026-27) →

What you get in the pack

All chapters in this pack

  1. PYQ Ch 1 Python Revision Tour
  2. PYQ Ch 2 Functions
  3. PYQ Ch 3 Exception Handling
  4. PYQ Ch 4 Text Files
  5. PYQ Ch 5 Binary Files
  6. PYQ Ch 6 CSV Files
  7. PYQ Ch 7 Stack
  8. PYQ Ch 8 Computer Networks I: Evolution and Data Communication
  9. PYQ Ch 9 Computer Networks II: Devices, Topologies and Types
  10. PYQ Ch 10 Network Protocols and Web Services
  11. PYQ Ch 11 Database Concepts
  12. PYQ Ch 12 SQL: DDL, DML and Queries
  13. PYQ Ch 13 SQL: Aggregates, Grouping and Joins
  14. PYQ Ch 14 Interface of Python with MySQL
  15. Board Paper 2026 Set 91 with Solutions
  16. Board Paper 2025 Set 91 with Solutions
  17. Board Paper 2024 Set 91 with Solutions
← PYQ Ch 1 Python Revision Tour PYQ Ch 3 Exception Handling →

Prices shown in US dollars. Show prices in: ₹ INR · US$ USD