CHAPTER 1,2,3 Holiday HOMEWORK CLASS XII COMPUTER SCIENCE

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

1|Page

KENDRIYA VIDYALAYA HINOO 1ST SHIFT RANCHI


Summer Break Holiday Homework
Class: XII B(Session 2023-24)

CHAPTER 1, 2 & 3 : PYTHON REVISION TOUR I & II, WORKING WITH FUNCTIONS
ERROR FINDING QUESTIONS

Q 1. Find error in the following code(if any) and correct code by rewriting code and underline
the correction;-
x= int(“Enter value of x:”)
for in range [0,10]:
if x=y
print( x+y)
else:
Print( x-y)
Q 2. Rewrite the following program after finding and correcting syntactical errors and
underlining it.
a,b = 0
if (a = b)
a +b = c
print( z)
Q 3. Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
250 = Number
WHILE Number<=1000:
if Number=>750
print (Number)
Number=Number+100
else
print( Number*2)
Number=Number+50
Q 4. Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
Val = int(rawinput("Value:"))
Adder = 0
for C in range(1,Val,3)
Adder+=C
if C%2=0:
Print (C*10)
Else:
print (C*)
print (Adder)
Q5. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
25=Val
for I in the range(0,Val)
2|Page

if I%2==0:
print( I+1)
Else:
print (I-1
Q6. Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
STRING=""WELCOME
NOTE""
for S in range[0,8]:
print (STRING(S))
Q 7. Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
a=int{input("ENTER FIRST NUMBER")}
b=int(input("ENTER SECOND NUMBER"))
c=int(input("ENTER THIRD NUMBER"))
if a>b and a>c
print("A IS GREATER")
if b>a and b>c:
Print(" B IS GREATER")
if c>a and c>b:
print(C IS GREATER)
Q 8. Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
i==1
a=int(input("ENTER FIRST NUMBER"))
FOR i in range[1,11];
print(a,"*=",i,"=",a*i)
Q. 9 Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
a=”1”
while a>=10:
print("Value of a=",a)
a=+1
Q 10. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.

Num=int(rawinput("Number:"))
sum=0
for i in range(10,Num,3)
Sum+=1
if i%2=0:
print(i*2)
Else:
print(i*3 print Sum)
Q 11. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.
weather='raining'
3|Page

if weather='sunny':
print("wear sunblock")
elif weather='snow':
print("going skiing")
else:
print(weather)
Q 12. Write the modules that will be required to be imported to execute the following code
in Python.

def main( ):
for i in range (len(string)) ):
if string [i] = = ‘’ “
print
else:
c=string[i].upper()
print( “string is:”,c)
print (“String length=”,len(math.floor()))
Q.13. 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 positive:"x
execmain()
Q 14.- Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code
x=integer(input('Enter 1 or 10'))
if x==1:
for x in range(1,11)
Print(x)
Else:
for x in range(10,0,-1):
print(x)
15.Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
30=To
for K in range(0,To) IF k%4==0:
print (K*4) Else:
print (K+3)
OUTPUT FINDING QUESTIONS

Q1 Find output generated by the following code:


p=10
q=20
4|Page

p*=q//3
q=p=q**2
print(p,q)
Q2 Find output generated by the following code:
Str=”Computer”
S=Str[-4:]
print(S*2)
Q3 Find out the output of the Following –
x=20
x=x+5
x=x-10
print (x)
x,y=x-1,50
print (x,y)

Q4 Find out the output of the Following –


for a in range(3,10,3):
for b in range(1,a,2):
print(b, end=’ ‘)
print ()
Q5 FIND OUTPUT OF FOLLOWING
x=10
y=5
for i in range(x-y*2):
print("%",i)
Q6. Find output
x="one"
y="two"
c=0
while c<len(x):
print(x[c],y[c])
c=c+1
Q 7:
for i in range(-1,7,2):
for j in range(3):
print(i,j)
Q.8
string=”aabbcc”
count=3
while True:
if string[0]=='a':
string=string[2:]
elif string[-1]=='b':
string=string[:2]
else:
count+=1
break
5|Page

print(string)
print(count)
Q9:
x="hello world"
print(x[:2],x[:-2],x[-2:])
print(x[6],x[2:4])
print(x[2:-3],x[-4:-2])
Q 10. Find and write the output of the following python code :
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)

Q 11. 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=200
B=20
A=Changer(A,B)
print A,"$",B
B=Changer(B)
print A,"$",B
A=Changer(A)
print A,"$",B

Q 12. Find and write the output of the following python code: 2
Data = ["P",20,"R",10,"S",30]
Times = 0
Alpha = ""
Add = 0
for C in range(1,6,2):
Times= Times + C
Alpha= Alpha + Data[C-1]+"$"
Add = Add + Data[C]
print Times,Add,Alpha

Q13 Find and write the output of the following python code:
6|Page

Text1="AISSCE 2018"
Text2=""
I=0
while I<len(Text1):
if Text1[I]>="0" and Text1[I]<="9":
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
elif Text1[I]>="A" and Text1[I] <="Z":
Text2=Text2 + (Text1[I+1])
else:
Text2=Text2 + "*"
I=I+1
print Text2
Q14 Find and write the output of the following python code:
TXT = ["20","50","30","40"]
CNT = 3
TOTAL = 0
for C in [7,5,4,6]:
T = TXT[CNT]
TOTAL = float (T) + C
print TOTAL
CNT-=1
Q 15
line = "I'll come by then."
eline = ""
for i in line:
eline += chr(ord(i)+3)
print(eline)

Q 16
line = "What will have so will"
L = line.split('a')
for i in L:
print(i, end=' ')

Q 17 Find output
p=5/2
q=p*4
r=p+q
p+=p+q+r
q-=p+q*r
print(p,q,r)
Q 18 find output
a=(2+3)**3-6/2
b=(2+3)*5//4+(4+6)/2
c=12+(3*4-6)/3
7|Page

d=12%5*3+(2*6)//4
print(a,b,c,d)
Q 19. Find the output of the following:
def main ( ) :
Moves=[11, 22, 33, 44]
Queen=Moves
Moves[2]+=22
L=Len(Moves)
for i in range (L)
print “Now@”, Queen[L-i-1], “#”, Moves [i]
Q 20. Find the output of the following
L1 = [100,900,300,400,500]
START = 1
SUM = 0
for C in range(START,4):
SUM = SUM + L1[C]
print(C, ":", SUM)
SUM = SUM + L1[0]*10
print(SUM)
Q. 21.Find and write the output of the following python code:
def fun(s):
k=len(s) m=" "
for i in range(0,k): if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else:
m=m+'bb' print(m)
fun('school2@com')
Q. 22. Find the output of the given
program :
def Change(P ,Q=30):
P=P+Q
Q=P-Q
print( P,"#",Q)
return (P)
R=150
S=100
R=Change(R,S)
print(R,"#",S)
S=Change(S)
23.
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")
8|Page

Questions Based on Tuple


Q: Find the output of following codes
1. t1=("sun","mon","tue","wed")
a. print(t1[-1])

2. t2=("sun","mon","tue","wed","thru","fri")
for i in range (-6,2):
print(t2[i])

3. t3=("sun","mon","tue","wed","thru","fri")
if "sun" in t3:
for i in range (0,3):
print(t2[i])
else:
for i in range (3,6):
print(t2[i])

4. t4=("sun","mon","tue","wed","thru","fri")
if "sun" not in t4:
for i in range (0,3):
print(t4[i])
else:
for i in range (3,6):
print(t4[i])

5. t5=("sun",2,"tue",4,"thru",5)
if "sun" not in t4:
for i in range (0,3):
print(t5[i])
else:
for i in range (3,6):
print(t5[i])

6. t6=('a','b')
t7=('p','q')
t8=t6+t7
print(t8*2)

7. t9=('a','b')
t10=('p','q')
t11=t9+t10
print(len(t11*2))
8. t12=('a','e','i','o','u')
p,q,r,s,t=t12
print("p= ",p)
print("s= ",s)
9|Page

print("s + p", s + p)

9. t13=(10,20,30,40,50,60,70,80)
t14=(90,100,110,120)
t15=t13+t14
print(t15[0:12:3])
Q. Find the errors
1. t1=(10,20,30,40,50,60,70,80)
t2=(90,100,110,120)
t3=t1*t2
Print(t5[0:12:3])
2. t1=(10,20,30,40,50,60,70,80)
i=t1.len()
Print(T1,i)
3. t1=(10,20,30,40,50,60,70,80)
t1[5]=55
t1.append(90)
print(t1,i)
4. t1=(10,20,30,40,50,60,70,80)
t2=t1*2
t3=t2+4
print t2,t3

5.
t1=(10,20,30,40,50,60,70,80)
str=””
str=index(t1(40))
print(“index of tuple is ”, str)
str=t1.max()
print(“max item is “, str)

List Based Question


Q.1. Give the output of the following code:-
list=['p','r','o','b','l','e','m']
list[1:3]=[]
print(list)
list[2:5]=[]
print(list)
Q 2. Give the output of the following code:-
l1=[13,18,11,16,13,18,13]
print(l1.index(18))
print(l1.count(18))
l1.append(l1.count(13))
print(l1)
10 | P a g e

Q 3 Find the error in following code. State the reason of the error.
aLst = { ‘a’:1 ,’ b’:2, ‘c’:3 }
print (aLst[‘a’,’b’])
Q 4. list1 =[1998, 2002, 1997, 2000]
list2 =[2014, 2016, 1996, 2009]

print"list1 + list 2 = : ", list1 +list2 #statement 1

print"list1 * 2 = : ", list1 *2 #statement 2

Q5. list1 = [1, 2, 3, 4, 5]


list2 =list1
list2[0] =0;
print("list1= : ", list1)
Q6. What is the output of the following:
data =[2, 3, 9]
temp =[[x forx in[data]] forx inrange(3)]
print(temp)
a) [[[2, 3, 9]], [[2, 3, 9]], [[2, 3, 9]]]
b) [[2, 3, 9], [2, 3, 9], [2, 3, 9]]
c) [[[2, 3, 9]], [[2, 3, 9]]]
d) None of these
Q7.
temp =['Geeks', 'for', 'Geeks']
arr =[i[0].upper() fori intemp]
print(arr)
a) [‘G’, ‘F’, ‘G’]
b) [‘GEEKS’]
c) [‘GEEKS’, ‘FOR’, ‘GEEKS’]
d) Compilation error
Q8.What will be the output?
1. d1 ={"john":40, "peter":45}
2. d2 ={"john":466, "peter":45}
3. d1 > d2
a) TRUE
b) FALSE
c) ERROR
d) NONE

Q9. What will be the error of the following code Snippet?


Lst =[1,2,3,4,5,6,7,8,9]
Lst[::2]=10,20,30,40,50,60
Print[Lst]
Q10. Find the error in following code. State the reason of the error
aLst={‘a’:1,’b’:2,’c’:3}
print(aLst[‘a’,’b’])
Q11. What Will Be The Output Of The Following Code Snippet?
11 | P a g e

a =[1,2,3,4,5]
print(a[3:0:-1])
A. Syntax error
B. [4, 3, 2]
C. [4, 3]
D. [4, 3, 2, 1]
Q 12.What Will Be The Output Of The Following Code Snippet?
fruit_list1 = ['Apple', 'Berry', 'Cherry', 'Papaya']
fruit_list2 = fruit_list1
fruit_list3 = fruit_list1[:]
fruit_list2[0] = 'Guava'
fruit_list3[1] = 'Kiwi'
sum = 0
for ls in (fruit_list1, fruit_list2, fruit_list3):
if ls[0] == 'Guava':
sum += 1
if ls[1] == 'Kiwi':
sum += 20
print (sum)
A. 22
B. 21
C. 0
D. 43
Q13. What Will Be The Output Of The Following Code Snippet?
a = {(1,2):1,(2,3):2}
print(a[1,2])
A. Key Error
B. 1
C. {(2,3):2}
D. {(1,2):1}
Q14. What Will Be The Output Of The Following Code Snippet?
my_dict = {}
my_dict[1] = 1
my_dict['1'] = 2
my_dict[1.0] = 4
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
A. 7
B. Syntax error
C. 3
D. 6
Q15.What Will Be The Output Of The Following Code Snippet?
my_dict = {}
my_dict[(1,2,4)] = 8
my_dict[(4,2,1)] = 10
12 | P a g e

my_dict[(1,2)] = 12
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
print(my_dict)
A. Syntax error
B. 30
{(1, 2): 12, (4, 2, 1): 10, (1, 2, 4): 8}
C. 47
{(1, 2): 12, (4, 2, 1): 10, (1, 2, 4): 8}
D. 30
{[1, 2]: 12, [4, 2, 1]: 10, [1, 2, 4]: 8}

QUESTION BANK ON OUTPUT AND ERROR BASED QUESTIONS ON FUNCTIONS IN


PYTHON

Q. Identify the errors, underline it and correct the errors

a)Def Sum(a=1,b)
return a+b
print (“The sum =” Sum(7,-1)

b) def main ( )
print ("hello")

(c) def func2() :


print (2 + 3)

func2(5)

Q1. Find the output of the following numbers:


Num = 20
Sum = 0
for I in range (10, Num, 3)
Sum+=i
if i%2==0:
print
i*2
else:
print i*3
Q2.Find the output of the following
Text=”gmail@com”
13 | P a g e

L=len(Text)
ntext=” “
For i in range (0,L):
If text[i].isupper():
ntext=ntext+text[i].lower()
elif text[i].isalpha():
ntext=ntext+text[i].upper()
else:
ntext=ntext+’bb’
Q3. def power (b , p):
r = b ** P
return r

def calcSquare(a):
a = power (a, 2)
return a

n=5
result = calcSquare(n)
print (result )

Q 4. Find the output of the following-


Import math
print (math. Floor(5.5))
Q 5. Find the output
def gfg(x,l=[]):
for I in range(x):
l.append(i*i)
print(l)
gfg(2)
gfg(3,[3,2,1])
gfg(3)
Q 6. count =1
def dothis():
global count
for I in (1,2,3)
count+=1
dothis()
print count
Q 7. def addem(x,y,z):
Print(x+y+z)
def prod(x,y,z):
return x*y*z
A=addem(6,16,26)
B=prod(2,3,6)
Print(a,b)
Q 8. def Func(message,num=1):
14 | P a g e

print(message*num)
Func(‘python’)
Func(‘easy’,3)

Q 9.def Check(n1=1,n2=2)
n1=n1+n2
n2+=1
print(n1,n2)

Check()
Check(2,1)
Check(3)
Q. 10. a=10
def call():
global a
a=15
b=20
print(a)
call()

11.Write a user defined function GenNum(a, b) to generate odd numbers between a and b
(including b)
12.. Write definition of a method/function AddOdd(VALUES) to display sum of odd
values from the list of VALUES.

13..Write definition of a Method MSEARCH(STATES) to display all the state names


from a list of STATES, which are starting with alphabet M.
For example:
If the list STATES contains
[“MP’,”UP”,”MH”,”DL”,”MZ”,”WB”]
The following should get displayed
MP
MH
MZ
14...Write a python function generatefibo(n) where n is the limit, using a generator function
Fibonacci (max)( where max is the limit n) that produces Fibonacci series.

15. Write a definition of a method COUNTNOW(PLACES) to find and display those place
names, in which
There are more than7 characters.For example :If the list PLACES contains.
3
["MELBORN","TOKYO","PINKCITY","BEIZING","SUNCITY"
The following should get displayed :PINKCITY
15 | P a g e

General Theory questions

1.Differentiate between the round() and floor() functions with the help of suitable example.
2.Which string method is used to implement the following:
a. To count the number of characters in the string
b. To change the first character of the string in capital letter
c. To change lowercase to uppercase letter
d. To check whether the given character is letter or a number

3.What are default arguments ?


4.What is the difference between actual and formal parameters ?
5.What is a recursive function ?
6.What is the difference between built-in functions and modules?
7.what is the difference between local variable and global variable?
8.What are the advantages of writing functions with keyword arguments ?
9. What do you mean by scope of variables ?
10. Which of the following is valid arithmetic operator in Python:
(i) // (ii) ? (iii) < (iv) and
11. Write the type of tokens from the following:
(i) if (ii) roll_no
12. Which of the following are valid operators in Python:
(i) ** (ii) */ (iii) like (iv) ||
(v) is (vi) ^ (vii) between (viii) in
13. Which of the following can be used as valid variable identifier(s) in Python?
(i) 4thSum
(ii) Total
(iii) Number#
(iv) _Data

You might also like