Cs Revision Class 11
Cs Revision Class 11
Fuctiens
FUNCTIONS
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
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
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)
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
13.
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
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.
St=I
12
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:
3$3
a,b, y=7,8,3234
x
fun(15, 72)
printía, b, x yl 19.Find the output of below:
doThis) runme(a, b)
print(count)
def change(msg): 2
A=100
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():
Data
)
1Wnte the output ofthe following python code. IM
2
0
a
def change(a):
Netei
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
print(a+b+c)
print(X,"#)
Hint: A function without an explicit return statement returns None
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.
RAMAN* factsas=p
2121
um==0:
factest=1
yooRAJ*
33 factst=2
TARA
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)
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)
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?
d. call
return
my
my func
func)
pnt Aginal Istih) 39.What will be the output of the following Python code?
a. 50
b.0
EDkeplacdyCd c.
dNone
Null
DOMS Paga No.
Dato
DOMSPageNo.
Date
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)):
i
if(str[i].
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
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.
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
k=len(s)
global a
a-15
if(s[i).isupper)) print(a)
call()
m-m+si].lower()
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
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