CS_XII_Functions_Assignment_2023-24[1]
CS_XII_Functions_Assignment_2023-24[1]
CLASS XII
COMPUTER SCIENCE (083)
9. Write a python function findsum(x,n) to find the sum of first n terms of the following
series:
x – x2 + x3 – x4….
where n and x have to be the input from the user. The function should have 2
parameters n and x and should return the sum of the series.
10.Write a Python function arrangenum(L) that accepts the list L of integers and sets all
negative elements to the left and positive elements to the right of the list.
If L= [1,-2,3,4,-5,7]
The output should be: [-5,-2, 3,4,7]
11.Write the output for the following codes:
(i) def myfunc(a, b=5, c=10):
print('a is', a, 'and b is', b, 'and c is', c)
myfunc(3, 7)
myfunc(25, c = 24)
myfunc(c = 50, a = 100)
(ii) x = 150
def myfunc():
global x
print('x is', x)
x=2
print('Changed global x to', x)
myfunc()
print('Value of x is', x)
(iii) num = 1
def func():
global num
num = num + 3
print(num)
func()
print(num)
(v) a=1
def test():
a=10
print(a)
MULTIPLE CHOICE QUESTIONS.
1. What is the output of the following code?
def display(msg):
print(msg, 'is a habit.')
display('Creativity')
a) is a habit
b) Creativity is a habit.
c) is a habit. Creativity
d) Creativity
2. In python which keyword is used to start function?
a) function
b) import
c) def
d) try
3. Which one of the following is the correct way of calling a function?
a) function_name()
b) call function_name()
c) ret function_name()
d) function function_name()
calc(5)
a) 5
b) 6
c) 9
d) 4
x=10
f1()
print(x)
a) 11
b) 10
c) error
d) 12
x=100
def f1():
global x
x=90
def f2():
x=80
f1()
f2()
print(x)
a) 100
b) 90
c) error
d) 80
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')
a) schoolbbbbcom
b) schoolbbcom
c) SCHOOLbbbbCOM
d) school@com
14.Find and write the correct 3 outputs of the following python code:
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)
a) 150 # 250
b) 150 # 100
c) 100 # 130
d) 250 # 150
e) 250 # 100
f) 130 # 100
a=10
def call():
global a
a=15
b=20
print(a)
call()
a) 20
b) 35
c) 15
d) 10
calcresult()
a) 49
b) 25
c) 9
d) 1
makenew(“sTUdeNT")
a) The new string is : STUDENTs
b) The new string is: S1U3E5Ts
c) The new string is: STUDE5tS
d) The new string is: StuDE5Ts
a) [11, 10, 9, 8, 4, 7]
b) [11, 10, 9, 8, 7, 4]
c) [11, 10, 9, 8, 7, 3]
d) [11, 10, 9, 8, 6, 4]
22.Find and write the correct 3 outputs of the following python code:
def func(a, b=5, c=10):
print('a =', a, ',b =', b, ', c =', c)
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100)
a) a = 3 , b = 7 , c = 10
b) a = 25 , b = 5 , c = 24
c) a = 15 , b = 100 , c = 50
d) a = 25 , b = 100 , c = 7
e) a = 5 , b = 10 , c = 50
f) a = 100 , b = 5 , c = 50
g) a = 5 , b = 100 , c = 50
a) 1 , 2 and 4
b) 2&3
c) 1 &4
d) 3&4
27.Arguments inside the parentheses of a function header that can receive a value?
a) Actual Arguments
b) Formal Arguments
c) Global Arguments
d) None of the above
a) BGEL
b) LEGB
c) GEBL
d) LBEG
a) 3 3 b) 5 3 c) 2 3 d) None
30.What will be the output of the following code?
def my_func(num1,num2=10):
num1+=num2
return num1
print(my_func(50),my_func(30,20))
a) 50 60 b) 50 c) 60 50 d) 30 50
a) 2 b) -2 c) 12 d) 5
a) 5@4@7@8@
b) 25@4@35@8@
c) 25@20@35@40@
d) 5@20@7@40