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