0% found this document useful (0 votes)
27 views11 pages

Cs Revision Class 11

Revision for class 11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views11 pages

Cs Revision Class 11

Revision for class 11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Date

Fuctiens
FUNCTIONS

1.Consider the code given below:


b-100
def tcst(a):
missing statement
b-bta
print (a,b)
test (10)
print (b)

Which of the following statements should be given in the blank tor

#Missing Statement, if the output produced is 110?


Options:
a. global a
b. global b=100
Ler global b
d. global a=100

number. Observe the


2. Ine code givenbelow accepts a number as an argumentand returns the reverse
and rewrite it after removing all syntax and logical errurs. Underline
alf the
tollowing code carefully
corections made.

define revNumber (num)


Lev
:
rem
While
remnum
num>
10
0: Lohle nm>O/
rev*10 rem
num num//10 rev=reI0-+re
nun= mio
print (revNumber(1234))
prrtythinbo (1234)
3.Writea function countNow(PLACES) in PLACES asan argument
Python, that takes the dictionary,
anddisplays names (in uppercase)of the places
the are longer whose names 5 than characters.
For example,Consider the following dictionary
PLACES={1:"Delhi",2:"London"3:"Paris",4:"NewYork"5:"Doha")
The output should be:
LONDON
NEW YORK

4.Writea 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 "Comelet us have some fun",
the tuple will have (4,3, 2,4, 4, 3)
DOMSPaga No.
Dato

4:"New York', 5Dubai


do csuyitnou) (LACES):
fen plaçe PLACES. laluesC):
lese lace) >5:

CautnsLACES)

endaST NG-ltl)

):

3RTNGnSt
(hod
)
ength = Zen
T (length + )
rehenmé let have Senae fan
5.Writethe Python statement for each of the following tasks using BUILTIN functions/ methods only:
() To insert an element 200 at the third position, in the list L1.

(ü) To check whether astring named, message ends with a full stop/ period or not.

Lhasent (2200)
t Code

Sc mitnt ni thr rlleing cnde

ama?
h, B, se3 Ymana
resnMan
maximm value from
return che
to find and the corrections
rking program and inderane
grogremmer the code

B
7Atione in prth
ens. Besrie
n
The cnde wioe hel oatica
y
he ist
made

MÂTHSMATHS

8A4 65 7D
9.
code given below:
Predict the output of the
de ma kenew (mystr):
newstr
count-0
for i in mystr:
i£ cOunt 82!0
newatrnewstrtatr (count)

8Wn oucpu heiow code:

1f i.lower ():
newatrnewStr+iupper

()
6lse
newstnewati
Counttl
et print (newstr)
ma kenew ("No@1")

Assertion (A If the arguments in function call statemest mach the oumber and orler of argumens as
deoed in the tunetion detinition, such anguments are called ponitional argumens.

Io-0$20 Reasoning
ponitiosal
(R-Dung
argumeni(a)
a function call, the argunent tise fint contaias detaukt argunents) followed by

(a)Boh A asd R are re


and Ris the coect esplanation for A
(bì Bedi A asd R are Une and R iN not the coect explanation for A
(3AsTrue but R is False
fdA is false but Ru True
Pago No.
Date
Dato

13.

the code given below:


Wite the output of

IOA:
P5
def

a10
bs
sum(q,r-2):
global p
prtq*
print(p,
end )
sum(a,b)
sum(r-5,q-1)

139ei105#6+
theRewrite following codein python after removing all syntax

done in the code


error(s). Underline cach correction

#Methodto find sum


def Sum(Count)
S=0
breat
for lin Range(1, Count+1):

S+=|

RETURNS
Call
11.Rao has written a code to input a number and check whether it is prime or noL. His code is having print Sum[2] #Function
errors. Rewrite the correct code and underline the correcions made.

def prime ():


n=int (input ("Enter number to check :: ")
for i in range (2, n/2) :
if ni-0:
print ("Number is not prime \n")
break
else:
print ("Number is prime \n')

St=I
12

Predict the output of the Python code given below:


def Diff(N1,N2):
N1>N2: pnt(Sun(2)
if
retun N1-N2
else:
return N2-NI o
NUM= [10,23,14,54,32]
A-NUMCNT]
B=NUM[CNT-1]
2
for CNT in mange (4.0,1);-44+3Z|

6
39
print(Diff(A,B), #,end=") 6

J2A:22#40#9#13#
5OMSg No

of below:
2M
Dut output
18. Find the

32 num100
188
34
0 43 30 32
def calc(x):
num
1S Fnd the output of below
sorint: 1Sl: 34 global
if x>2:

def funfa, b): num=1


a 10 else:
global xy Galeleal num=2
5-20
5=43
c=30
ao
c43
alz
b|
return(num%2)
num=1000
result=calc(num)
print(a,b,cxy)
C30 print(num,":",result)

3$3
a,b, y=7,8,3234
x
fun(15, 72)
printía, b, x yl 19.Find the output of below:

16Find the outout of below script def runme(x=1, y=2): 3 # 3


Count I
X= X+y
y+=1
def doThis)
print(x, '$', y)
global count
return x,y
for in (1,2, 31:
= runme()
I
a,b
count --123 print(a, '#, b)

doThis) runme(a, b)
print(count)

Find the output of below:


20.
17. Fand the output of below 3M

def change(msg): 2
A=100

def Change(P ,Q=R}: 200## \\oà n = len(msg) 2

P=P+Q
new msg ="
250## |50

u
Q-P-Q
6
print( P."#,Q)
250 ## /00 for i in range(0,n):

return (P)
200## |00 not msgli].isalpha():

if
new msg = new msg + @'
S-100
else:
R=Change(R,S)

print(R,"#S) if msg{i].isupper():

S-Change(S) new_msg new_msg + msgli*2


else:

new_msg = new msg + msglil


return new msg

new_msg = change('15 New Men)2


print(new_msg)
Pan No

Data

)
1Wnte the output ofthe following python code. IM
2
0
a

def change(a):
Netei

btneglecthq the ctChs the Guu


(9):
a a+10
dd changg "a-atio e
hange (0)
changea)
pnt(a) PPntta) GMAILbbCOM
of the following python code:
print(a) 25.Find and write the output

function definition. Identify ,Y=10):


the following function calls with respect to thc
22 def Change(X
Consider

which of these will cause an cror and why? (3M) X=X+Y

def calculatc(a.b-S,e-10):
XXY
return ab-c
print( X,",Y)

W calculate( 2,3)
tllenoSA return (X)
1
grgumunt
2calculate(e-50,35)>l aluesta X-5

diaculate 20,b-7,a-15Rse Y=20


4. calculate(x-10,b-12> enpected X=Change(X,Y)

23. What will the following function return? 1M print(x,"#Y)

def add(a,b,c): Y=Change(Y)

print(a+b+c)
print(X,"#)
Hint: A function without an explicit return statement returns None

24. Find the output of the following 2M


2E9 5 #2
def textchanger(text): 5#2
L= len(text) 2# LO
ntext="n

for i in range(0,L) : function: 2M


26. Consider the following
if text [i].isupper() : 266
ntext =ntext + text[i].lower()
def interest (prin,cc,time=2,rate=0.09):
elif text [0.isalpha():
return prin" timerate
ntext = ntext + text[i).upper()
else: reason?
call is valid write with
Which function
ntext - ntext + "bb'
94.interest(rate=0.12, prin=5000,cc=4
print(ntext)
Wb. interest(5000,3,rate=0.05)
textchanger('gmail@com') Kc interest(rate=0.05,5000,3) aorpnt fol
Date

274 find the


Butpti
def
ChangeList:
L=0
L1=0
L2-1
for iin pint
range(1,10):
ececman)
Lappendi)
for iin
range(10,1,2):
L1.append(1)

for iin
range(len(L1)):
docal eiales
L2.append(L1[1]+L[)

2.append
print(2)
(len(L)-Ien(L1))
Dded utEde all

Changelstt C)
Ahe entire
rign
2R 28. Observe the following Python code and rewTite it after removing all syntactical
errors with each correction
underlined. 2M unctind recutibn he
dusction cfthe
DEF execmain):
x = input("Enter a number:")
if (abs(x-x):

You entered
print("

else:
a positive number")
Enguited
X=*-]
print "Number made positive:"x
execmain()

Se: DE
def ececmain)
mpt("Entes a nudea:) funchen
DOHSPage

Na.
Data

te add
Cch ap
thesé ues
the l tess=(200)456300l0o,234,6787
(Sc8es)sy678]
def adtu (Numbgs)
S=e Cnding
Pintls)
n=nhunes)
Mst=RA-HN', 21YCGRAT'3ARH)

pntls)
JI. Wite the definition ofa method ZeroEndine(SCORES) to add all those valuCs in

the list of SCORES, which are ending with zero (0) and display the sum.

For example: If the SCORES contain (200, 456, 300, 100, 234, 6/s1
The sum should be displayed as 600
ie prihe nys ajumit
32.Write a method in python to display the elements of list twice, if is a number and
it
display the element terminated with *ifit is not a number.

For example, if the content of list is as follows:

MyList-['RAMAN'," YOGRAJ,'3, TARA]


21
The output should be

RAMAN* factsas=p
2121

um==0:
factest=1
yooRAJ*
33 factst=2
TARA

total=oo pímenersnd.pimes (N)


Paso No
Date

30M5PagaNo
IÔ 2030
Data
34.Find the outout of

a=90
belov
348
b=10o
def fun (c, d) : 36 Whioh of the following
componchts are part of a function header
globa a in Pthon?
a= 10 a. Function Name
C,d= d,c
b 20 b. Retum Statement
d=70
C= 30 c. Parancter List

e=90 c
print (a,b, c) d Bothaand

C,d 1, 2
fun (50, 100) 37Which of the following function header is corect)
print (a, b, C,d)
f=76 a. def cal_si(p=100, r, t-2)

35 b. def cal si(p=100, -8,t)

Write a function EORenlace) in Python, which accepts a list L of c.def cal si(p, r-8, )
numbers. Thereafter,it increments alleven numbers by l and decrements ddef cal _si(p,r-8, t-2)

all odd numbers by 1.

Example:
If SampleInput data of the list
L=(10, 20,30,40,35,55)
is : 38 Which of the following

A my func)
is the correct way to call a function?

Output be: will


b. def my func)
L-(11,21,31,4l,34,54)

35Sala del FDReglace : C.

d. call
return

my
my func

func)

pnt Aginal Istih) 39.What will be the output of the following Python code?

def add (numl,num2):


sum = numl + num2
alt=| sum = add(20,30)
print(sum)

a. 50

b.0

EDkeplacdyCd c.

dNone
Null
DOMS Paga No.
Dato

DOMSPageNo.
Date

40 What will be the output of the following code?


the output the following Python code:
44,Find and write

of
42
def my_func(var|=100, var2-200): def Display (str):
t of the following code
varl+10 What is the output
snippen m-""
var2 var2- 10 def Change Val(M,N):
for i in range(0,lern(str)):

return varl +var2 for in range(N):


isupper):

i
if(str[i].

print(my func 50)my if MI]%5 =0:


m=m+str[i].lower)
func(0)

a 100 200 M[1//=5 elif str[i] islower():

b. 150 300 if M[ij%3 =0: m=m+str[i].upper(0

M[iJ/=3 else:
c 250 75
if i%2-0:
1s0 300 L= (25,8,75, 12]
Change Val(L,4) m-mtstr[i-1]

for i in L: else:
41

What will be the output of the following code? print(i,end-"#")


m-m""
Ivalue - 50 a) 5#8#15#4# print(m)

del display (N @Python3.01)


by 548#5#4# Display('Fun

glchal value

value 25
c) 5#8#1 5#14#
4h8l:
45 Write
fUNtplTHONn#.
a function LShift(Arr,n) in Python,
d) 5#18#1 5#4# which accepts a list Arr of numbers

and n is a numeric value by which all elements of the list are shifted to lef
value value N
43.What will be the output of the following code? Sample Input Data of the list
edse.

value value - N X=3 Arr- [10,20,30,40,12,11], n=2

print(value, end) def myfunc): Output

3, displayt(20) global x Arr = [30,40, 12,11,10,20]

printvalue) X+2

bSo5
print(x, end=) L=lbal
print(x, end) t,n):
myfunc)
d.Se501

print(x, end')

y384: 3 55
st Eo, 60,70,40,1D 20,20,3).
Dato
Pagt No.

Date

python code:
andwrite the output of the following
48 Find
of thefollowing python code:
46.Find and write the output
a 10

def fun(s): def call):

k=len(s)
global a

a-15

for i in range(0,k): b-20

if(s[i).isupper)) print(a)

call()
m-m+si].lower()

elif s[i].isalpha(): How can you


by local and global scope of variables?
understand
49.What do you with same
m=m+si].upper() if function has a variable
the function,
varíable inside
access a global
else:
name.
m=m+bb'

print(m)

fun('school2 @ com")
Cutside any uncter
ARL:SCHOOLbbbbCDM code: lacessed m cuy puntte n tha Jpoam
and write the output of the following python
47. Find

def Change(P ,Q=30):


P-P+Q

Q-P-Q Slan be aLcesKh enly En lct


print( P,"#,0) n
return (P)

R150
Genctien
S 100
ncen haa
R-ChangeR,S)
the n2siaßle nane.
print(R,"#",S)

S-Change(S)
150
473l:2504#JD0
250+#
130100

You might also like