worksheet for python functions, Assignments of Computer science

cbse class 12 python worksheet for chapter 3

Typology: Assignments

2025/2026

Available from 02/27/2026

gomathivetrivel
gomathivetrivel 🇮🇳

28 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
OXALISS INTERNATIONAL SCHOOL (CBSE),
THACHUR.
Computer Science (083)
Class: XII Session: 2026-27
WORKSHEET 2
WORKING WITH FUNCTIONS
1. The code provided below is intended to check a number whether it is
perfect number or not. However, there are syntax and logical errors in the
code. Rewrite the code in python after removing all error(s). Underline each
correction done in the code.
def Perfect_Number( ):
n=input(int("Enter a number: "))
sum=0
for i in range(1,n):
if n%i==0:
sum=+i
if N==sum:
print("Perfect number")
else:
print("Not a perfect number")
Perfect_Number( ):
2. Vivek has written a code to input a number and check whether it is even or
odd number. His code is having errors. Rewrite the correct code and
underline the corrections made.
Def checkNumber(N):
status = N%2
return
#main-code
num=int (input (“Enter a number to check :))
k=checkNumber(num)
if k = 0:
print (“This is EVEN number”)
else:
print (“This is ODD number”)
3. Rewrite the following Python program after removing all the syntactical
errors (if any),
underlining each correction:
def checkval
x = input ("Enter a number")
if x % 2 =0:
print (x, "is even")
elseif x<0:
print (x, "should be positive")
else:
print (x, "is odd")
4. Mani Ayyar, a python programmer, is working on a project which requires
him to define a function with name CalculateInterest( ).
He defines it as:
def CalculateInterest (Principal, Rate=.06, Time): # Code
But this code is not working; Can you help Mani Ayyar to identify the error
pf3
pf4
pf5

Partial preview of the text

Download worksheet for python functions and more Assignments Computer science in PDF only on Docsity!

OXALISS INTERNATIONAL SCHOOL (CBSE),

THACHUR.

Computer Science (083)

Class: XII Session: 2026-

WORKSHEET 2

WORKING WITH FUNCTIONS

  1. The code provided below is intended to check a number whether it is perfect number or not. However, there are syntax and logical errors in the code. Rewrite the code in python after removing all error(s). Underline each correction done in the code. def Perfect_Number( ): n=input(int("Enter a number: ")) sum= for i in range(1,n): if n%i==0: sum=+i if N==sum: print("Perfect number") else: print("Not a perfect number") Perfect_Number( ):
  2. Vivek has written a code to input a number and check whether it is even or odd number. His code is having errors. Rewrite the correct code and underline the corrections made. Def checkNumber(N): status = N% return #main-code num=int (input (“Enter a number to check :)) k=checkNumber(num) if k = 0: print (“This is EVEN number”) else: print (“This is ODD number”)
  3. Rewrite the following Python program after removing all the syntactical errors (if any), underlining each correction: def checkval x = input ("Enter a number") if x % 2 =0: print (x, "is even") elseif x<0: print (x, "should be positive") else: print (x, "is odd")
  4. Mani Ayyar, a python programmer, is working on a project which requires him to define a function with name CalculateInterest( ). He defines it as: def CalculateInterest (Principal, Rate=.06, Time): # Code But this code is not working; Can you help Mani Ayyar to identify the error

in the above function and with the solution?

  1. Kavi has written a function to print Fibonacci series for first 10 element. His code is having errors. Rewrite the correct code and underline the corrections made. Some initial elements of Fibonacci series are: def fibonacci() first=0 second= print((“first no. is “, first) print (“second no. is,second) for a in range (1,9): third=first+second print(third) first,second=second,third fibonacci()
  2. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. 25 = Num WHILE Num<=100: if Num=>50: print(Num) Num=Num+ else print(Num*2) Num=Num+
  3. The code provided below is intended to swap the first and last elements of a given tuple. However, there are syntax and logical errors in the code. Rewrite it after removing all errors. Underline all the corrections made. def swap_first_last(tup) if len(tup) < 2: return tup new_tup = (tup[-1],) + tup[1:-1] + (tup[0]) return new_tup result = swap_first_last((1, 2, 3, 4)) print("Swapped tuple: " result)
  4. Atharva is a Python programmer working on a program to find and return the maximum value from the list. The code written below has syntactical errors. Rewrite the correct code and underline the corrections made. def max_num (L) : max=L(0) for a in L : if a > max max=a return max
  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=*‐ print "Number made positive:x”

total=a+b print(total) add (6,6) print(total)

  1. Find and write the output of the following Python code: def changer(p,q=10): p=p/q q=p%q print(p,"#",q) return p a= b= a=changer(a,b) print(a,"$",b) a=changer(a) print(a,"$",b)
  2. What will be the output of the following code? a = 15 def update(x): global a a += 2 if x%2==0: a *= x else: a //= x a=a+ print(a, end="$") update(5) print(a)
  3. Write the output of the code given below: def short_sub (lst,n) : for i in range (0,n) : if len (lst)>4: lst [i]=1st [i]+lst[i] else: lst[i]=lst[i] subject=['CS', 'HINDI', 'PHYSICS', "CHEMISTRY', 'MATHS'] short_sub(subject, 5) print(subject)
  4. Predict the output of the following: def Display(str): m="" for i in range(0,len(str)): if(str[i].isupper()): m=m+str[i].lower() elif str[i].islower(): m=m+str[i].upper() else: if i%3==0: m=m+str[i-1] else: m=m+"$"

print(m) Display('[email protected]')

  1. Predict the output of the Python code given below: def product(L1,L2): p= for i in L1: for j in L2: p=p+i*j return p LIST=[1,2,3,4,5,6] l1=[] l2=[] for i in LIST: if(i%2!=0): l1.append(i) else: l2.append(i) print(product(l1,l2))
  2. def Changer(P, Q = 10): P = P / Q Q = P % Q return P A = 200 B = 20 A = Changer(A, B) print(A, B, sep = '$') B = Changer(B) print(A, B, sep = '$', end = '###')
  3. 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 ‘indexList’ that stores the indices of all NonZero Elements of L. For example: If L contains [12,4,0,11,0,56] The indexList will have – [0,1,3,5]
  4. Write a function, lenWords(STRING), that takes a string as an argument and returns a tuple containing length of each word of a string. For example, if the string is "Come let us have some fun", the tuple will have (4, 3, 2, 4, 4, 3)
  5. Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES as an argument and displays the names (in uppercase)of the places whose names are longer than 5 characters. For example, Consider the following dictionary PLACES={1:"Delhi",2:"London",3:"Paris",4:"New York",5:"Doha"} The output should be: LONDON NEW YORK
  6. Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is a numeric value by which all elements of the list are shifted to left. Sample Input Data of the list Arr= [ 10,20,30,40,12,11], n=2 Output Arr = [30,40,12,11,10,20]