12th Standard CBSE Syllabus & Materials
12th Standard CBSE
CBSE 12th Economics Government Budget and the Economy Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Interface Python with MySQL - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Database Concept - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Data Communication - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Data Structures - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Python Revision Tour I - New Previous year Question Papers Study Material - QB365 Set A

Published on: 20/08/2026
Download CBSE Class 12th Standard CBSE Computer Science question papers, sample papers, important questions, and previous year solved papers in PDF format. Get free study materials, NCERT solutions, and exam preparation resources for Class 12th Standard CBSE Computer Science
Questions + Answers key
Take MCQ Computer Science Test

1.
(a) Predict the output of the following code:
def ExamOn (mystr):
newstr = " "
count = 0
for 1 in mystr:
if countleft!=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) Write the output on execution of the following Python code
def Change (X) :
for K.V in X.items() :
L1,append(K)
L2,append (V)
0 = (1:"ONE", 2:"TWO", 3:"THREE")
L1 = []
L2 = []
Change (D)
print (L1)
print (L2)
print (D)
2.
Riya was asked to accept a list of even numbers but she did not put the relevent condition while accepting the list of numbers. You are required to write a user defined function odd to even (L) that accepts the list L as an argument and convert all the odd numbers into even by multiplying them by 2
3.
Write a Python function generate fibo (n) where n is the limit, using a generator function Fibonacci (max) (where max is the limit n) that produces Fibonacci series.
4.
Write a user defined function find name (name) where name is an argument in Python to delete phone number from a dictionary phone book on the basis of the name, where name is the key
5.
Observe the following Python code very carefully and rewrite it after removing all syntactical errors with each correction underlined.
DEF execmain( ):
x = input ("Enter a number")
if (abs (x) = x):
print ("You entered a positive number:")
else:
x = * - 1
print ("Number made postive:" x)
execmain ( )
6.
Observe the following Python code carefully and obtain the output, which will appear on the screen after execution of it.
def Findoutput():
L - "earn"
x = "*"
count = 1
for i in L:
if i in ['a', 'e', 'i', 'o', 'u']:
X = X + i.swapcase()
else:
if count % 2 != 0:
X = X + str(len(L[:count]))
else:
X = X + i
count = count + 1
print(X)
Findoutput()
7.
The code given below accepts N as an integer argument and returns the sum of all integers from Ito N. Observe the following code carefully and rewrite it after removing all syntax and logical errors. Underline all the corrections made
def Sum (N)
for I in range (N):
S = S+I
return S
print (Sum (10)
8.
Write a Python method/function Count 3 and 7(N)to find and display the count of all those numbers which are between 1 and N, which are either divisible by 3 or by 7. For example: If the value of N is 15 The count should be displayed as 7 (as 3,6,7,9,12,14,15 in between 1 to 15 are either divisible by 3 or 7)
9.
Predict the output of the Python code given below:
def Diff(N1, N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM = [10, 23, 14, 54, 32]
for CNT in range (4, 0, - 1):
A=NUM[CNT]
B=NUM[CNT-1]
print(Diff(A,B),'非',end=' ')
10.
Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the function. The function returns another list named index List that stores the indices of all Non-Zero Elements of L
For example:
If L contains [12, 4, 0, 11, 0, 56]
The index List will have - [0, 1, 3, 5]
11.
Write a function EO Replace() in Python, which accepts a list L of numbers. Thereafter, increments all even numbers by l and decrements all odd numbers by 1.
Example:
If Sample Input data of the list is
L-[10.20,30.40.35,55]
Output will be:
L-[11,21,31,41,34,54]
12.
The code given below accepts a number as an argument and returns the reverse number. Observe the following code carefully and rewrite it after removing all syntax and logical errors. Underline all the corrections made define revNumber(num):
rev=0
rem=0
While num>0:
rem == num %10
rev = rev*10 + rem
num = num//10
return rev
print(revNumber(1234))
13.
Predict the output of the following code:
\(\begin{aligned} & \text { def } c a l l o n(b-20, a=10) \text { : } \\ & \quad b=b+a \\ & \quad a=b-a \\ & \quad \text { print }(b, \text { "\#", } a) \\ & \quad \text { return } b \\ & x=100 \\ & y=200 \\ & x=\operatorname{callon}(x, y) \\ & \operatorname{print}(x, \text { "@", } y) \\ & y=\operatorname{callon}(y) \\ & \operatorname{print}(x, \text { "@", } y) \end{aligned}\)
14.
The code given below accepts five numbers and displays whether they are even or odd: Observe the following code carefully and rewrite it after removing all syntax and logical errors:
Underline all the corrections made.
def Even Odd( )
for 1 in range (5):
num = int (input ("Enter a number")
if num/2=0:
print ("Even")
else:
print ("Odd")
Even Odd ( )
15.
What will be the output of the following? Explain.
a = 45
def Funl( ):
global a
print("Value of a is", a)
a = 5
print ("Changed global a to", a)
Fun1( )
print ("Value of a is", a)
16.
What will be the output of following code?
a = 45
def Funl( ):
global a
print("Value of a is", a)
a = 5
print ("Changed global a to", a)
Fun1( )
print ("Value of a is", a)
17.
What do you understand by local and global scope of variables? How can you access a global variable inside the function, if function has a variable with same name
18.
Why is it necessary to use the global keyword in Python? Explain with its effect on a variable inside a function.
19.
What is a default parameter? How is it specified?
20.
The function given below is written to accept a string s as a parameter and return the number of vowels appearing in the string. The code has certain errors. Observe the code carefully and rewrite it after removing all the logical and syntax errors. Underline all the corrections made.
def CountVowels(s):
c=0
for ch in range(s):
if 'aeiouAEIOU' in ch:
c=+1
return(ch)
21.
Explain the use of global key word used in a function with the help of a suitable example.
22.
Explain the use of global key word used in a function with the help of a suitable example.
23.
What is the difference between local variable and global variable? Also, give a suitable Python code to illustrate both.
24.
Differentiate between actual parameter(s) and formal parameter(s) with a suitable example for each.
25.
Rahul and Aryan both are friends. They want to display addition of age, subtraction of height, multiply of weight and division of IQ.
Rahul | Description |
|---|---|
Age | 32 |
Height | 175 cm |
Weight | 75 kg |
IQ | 100 |
Aryan | Description |
|---|---|
Age | 25 |
Height | 165 cm |
Weight | 75 kg |
IQ | 50 |
Firstly, define the function add, ( ), sub ( ), mul ( ) and div ( ).
26.
Here is the function to find the sum of arguments
total " __________ # Line 1
def sum (argl, arg2)___________ # Line 2
total = argl +___________# Line 3
print (total)
return___________ # Line 5
total = sum (10, 20)
print ( __________ ) # Line 7
(i) Which value or constant will be equal to variable total in line 1?
A 1
B 0
C 2
D None
(ii) Which symbol is used to terminate the function def in line 2?
A ;
B .
C :
D ,
(iii) Fill the blank in line 3
A sum
B 1
C arg2
D 0
(iv) Which value will be return in line 5?
A sum
B total
C True
D False
(v) Fill the blank in line 7.
A sum
B True
C False
D total
27.
A function is a block of organised and reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code re usability. The function blocks begin with the keyword def followed by the function name and parentheses ().
Any input parameters or arguments should be placed within these parentheses.
You can also define parameters inside these parentheses.
(i)Which keyword is used to define function?
(ii) Which type of bracket is placed after name of function?
(iii) A/An____________is a block of organised and reusable code.
(iv) Parameters are defined inside________
(v) Function is used to perform___________related action.
28.
These are the values provided in function call/ invoke statement. Required arguments are the arguments passed to a function in correct positional order. Keyword arguments are related to the function calls.
When you use keyword arguments in a function call, the caller identifies the arguments by the parameter name. A default argument is an argument that assumes a default value, if a value is not provided in the function call for that argument
(i) How many types of arguments are there in functions?
A 2
B 3
C 4
D 5
(ii) Which argument is an argument that assumes a default value?
A Default argument
B Positional argument
C Keyword argument
D None of the above
(iii) Which arguments are also known as positional arguments?
A Keyword argument
B Default argument
C Required argument
D Variable length argument
(iv) Which argument helps identify parameters by their names instead of position?
A Required argument
B Keyword argument
C Default argument
D Positional argument
(v) ____________are the values provided in function call/invoke statement.
A Functions
B Arguments
C Preprocessor
D Models
1.
(a) The new string is : gOn2Ge
Or (b) [1, 2, 3]
['ONE'. 'TWO'. 'THREE']
(1: 'ONE', 2: 'TWO', 3: 'THREE')
2.
def oddtoeven(L):
for i in range (len(L)):
if (L [i]% 2! = 0):
L [ i ] = L [ i ] ~ * ~ 2
print(L)
3.
def Fibonacci(max):
a = 0
b =1
while a <= max:
yield a
a, b = b, a + b
defgeneratefibo (n):
for i in Fibonacci(n):
print(i)
4.
def findname(name):
if name in phonebook:
del phonebook[name]
else:
print("Name not found")
print("Phonebook Information")
print("Name\t Phone no")
for 1 in phonebook:
print(1, "\t", phonebook[i])
5.
def execmain( )
x = input ("Enter a number")
if (abs (x)==x);
print ("You entered a positive
else: number :")
x* = -1
print ("Number made positive: ", x)
execmain( )
6.
Output
EA3n
7.
Corrected code
def Sum(N) :
s = 0
for I in range( 1, N+1 ):
S = S + I
return S
print(Sum(10))
8.
def Count 3 and 7(N):
C=0
for i in range(1,N+1):
if i %3==0 or 187==0:
C=C+1
print C
9.
22 # 40 #9 # 13 #
10.
def INDEX_LIST(L) :
indexList-[]
for a in range(0,len(L)):
if not L[a]==0:
indexList.append(a)
return indexList
print (INDEX_LIST(L))
11.
def EOReplace(L):
for i in range(len(L)):
if L[i]left==0:
L[i]=L[i]+1
else:
L[i]=L[i]-1
print(L)
EOReplace(L)
12.
Correct code is
def revNumber(num):
rev=0
rem=0
while num>0:
rem-num %10
rev=rev*10+rem
num=num//10
return rev
print (revNumber(1234))
13.
300#100
300@200
210#200
300@210
14.
def EvenOdd():
for i in range(5):
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
EvenOdd()
15.
Firstly call the function
f1( )
f2( )
Then output will be look like as:
Value of n 77
Value of n 77
16.
Output
Value of a is 45
Changed global a to 5
Value of a is 5
17.
A global variable is a variable that is accessible globally i.e everywhere the program. A local variable is one that is only accessible to the current scope, such as temporary variables used in a single function definition.
A variable declared outside of the function or in global scope is known as global variable. This means, global variable can be accessed inside or outside of the function where as local variable can be used only inside the function. We can access a global variable by declaring variable as global.
18.
• In Python, variables declared inside a function are local by default.
• If we want to modify a global variable from inside a function, we must declare it with the global keyword.
• This tells Python that we are referring to the variable in the global scope, not creating a new local variable.
• Without global, changes inside the function affect only a local copy, leaving the global variable unchanged.
19.
A parameter having default value in the function header is known as a default parameter. A parameter can be specified as default only if all the parameters on its right are specified as default. To specify a default parameter syntax is
def<function header> (arg1, arg2---arg x =<value>);
argx will now be a default parameter with default value as the value specified.
20.
def CountVowels ( s ) :
c = 0
for ch in s :
if ch in 'aeiouAEIOU' :
c += 1
return c
21.
In Python, global keyword allows the programmer to modify the variable outside the current scope.
It is used to create a global variable and make changes to the variable in local context. A variable declared inside a function is by default local and a variable declared outside the function is global by default. The keyword global is written inside the function to use its global value. Outside the function, global keyword has no effect
Example
c=10 # global variable
def add( ):
global c
c = c + 2 # global value of c is incremented by 2
print("Inside add( ):", c)
add( )
c=15
print("In main:",c)
Output
Inside add( ): 12
In main: 15
22.
In Python, global keyword allows the programmer to modify the variable outside the current scope.
It is used to create a global variable and make changes to the variable in local context. A variable declared inside a function is by default local and a variable declared outside the function is global by default. The keyword global is written inside the function to use its global value. Outside the function, global keyword has no effect
Example
c=10 # global variable
def add( ):
global c
c = c + 2 # global value of c is incremented by 2
print("Inside add( ):", c)
add()
c=15
print("In main:",c)
Output
Inside add( ): 12
In main: 15
23.
The differences between a local variable and a global variable are given below:
Local Variable | Global Variable |
|---|---|
These are declared within a function | These are declared outside all functions |
Local variable is accessible only with in a function in | Global variable is accessible throughout the program. |
It is also called an internal variable | It is also called an external variable |
The local variable of two functions may be declared with same name. | No two global variables in a program may have same name |
e.g. a = 10 #global variable
def value (i) :
c=0 #local variable
c = a + i
return c
Now call the function value
>>> value (5)
Output
15
24.
The list of identifiers used in a function call is called actual parameter(s) whereas the list of parameters used in the function definition is called formal parameter(s).
Actual parameter may be value / variable or expression. Formal parameter is an identifier.
Example
def area(side): # line 1
return side*side
print(area(5)) # line2
In line 1, side is the formal parameter and in line 2, while invoking area() function, the value 5 is the actual parameter.
A formal parameter, i.e. a parameter, is in the function definition. An actual parameter, i.e. an argument, is in a function call.
25.
def add(a, b):
print("ADDING % d + % d" % (a, b))
return a + b
def subtract(a, b):
print("SUBTRACTING % d - % d" % (a,b))
return a - b
def multiply(a, b):
print ("MULTIPLYING % d*% d" %(a, b))
return a * b
def divide(a, b):
print ("DIVIDING % d / % d" % (a, b))
return a/b
Now call these functions:
>>> age = add (32, 25)
#ADDING 32 + 25
>>> age
5 7
>>> height = subtract (175, 165)
#SUBTRACTING 175-165
>>> height
10
>>> weight = multiply (75, 70)
#MULTIPLYING 75 * 70
>>> weight
5250
>>> IQ = divide (100, 50)
#DIVIDING 100/50
>>> IQ
2
26.
(i) (B) Here total is the variable whose value is fixed during the execution of the program
(ii) (C) Python provides the def keyword to define the function the function def in line 2 is terminated with colon(:).
(iii) (C) Total is defined the sum of arg I and arg 2.
(iv) (B) This function will return the value of variable total.
(v) (D) Line 7 will print the value of total which is the sum of arg 1 and arg
27.
(i) def keyword used to define a function.
(ii) 0 (parentheses) Placed after the function name.
(iii) A function is a block of organised and reusable code.
(iv) Parameters are defined inside parentheses of the function.
(v) Function is used to perform single, related action.
28.
(i) (C) There are four arguments in functions as:
• Required arguments/Positional arguments.
• Keyword arguments
• Default arguments
• Variable length arguments
(ii) (A) A default arguments is an arguments that assumes a default value, if a value is not provided in the function call for that argument.
(iii) (C) Required arguments are also known positional argument. These arguments are the arguments passed to a function in correct positional order.
(iv) (B) Keyword argument
(v) (B) Argument are the values provided in function call/invoke statement. A function is a block of organised and reusable code that is used to perform a single, related action.
12th Standard CBSE Syllabus & Materials
12th Standard CBSE
CBSE 12th Business Studies Planning Important Questions And Answers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Business Studies Business Environment Important Questions And Answers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Business Studies Principles of Management Important Questions And Answers Study Material - QB365 Set A
NCERT Books
Syllabus
Exam Pattern
Sample Question Papers
Previous year Question Papers
Important Notes
MCQ Practice test
NCERT Exemplers
Case study Questions
Image Based Questions
Passage based Questions
HOT Questions
Value Based Questions
Model Questions Papers
NCERT ( Book Back ) Questions
Assertion and Reason
Important Questions And Answers
CBSE 12th Standard CBSE Subjects
CBSE Standards