Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Predict the output of the Python code given below:

def Diff(N1,N2):

if N1>N2:

return N1-N2


return N2-N1

NUM= [10,23,14,54,32]

for CNT in range (4,0,-1):



print(Diff(A,B),'#', end=' ')



Question 24 Choice 1 -Teachoo.png

Output: 22 # 40 # 9 # 13 #


  • The function Diff( ) takes 2 numbers as parameters and finds the difference by subtracting the smaller number from the larger number and returns the difference.
  • NUM is an array of 5 numbers.
  • The for loop iterates from 4 to 0 by decrementing by 1.
  • A and B are assigned 2 consecutive numbers from the array NUM and the difference is calculated and printed. This is repeated for all 2 consecutive numbers in the array.

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.