0% found this document useful (0 votes)
8 views

CS_XII_Functions_Assignment_2023-24[1]

This document is an assignment for Class XII Computer Science students at Bhatnagar International School, focusing on working with functions in Python. It includes a series of questions about function significance, parameters, scope, variable types, and several coding exercises. Additionally, there are multiple-choice questions to test the understanding of function concepts and outputs.

Uploaded by

clardie00
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

CS_XII_Functions_Assignment_2023-24[1]

This document is an assignment for Class XII Computer Science students at Bhatnagar International School, focusing on working with functions in Python. It includes a series of questions about function significance, parameters, scope, variable types, and several coding exercises. Additionally, there are multiple-choice questions to test the understanding of function concepts and outputs.

Uploaded by

clardie00
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

BHATNAGAR INTERNATIONAL SCHOOL, PASCHIM VIHAR

CLASS XII
COMPUTER SCIENCE (083)

TOPIC: WORKING WITH FUNCTIONS


ASSIGNMENT

Note: Attempt the following questions in your register.

1. What is the significance of having functions in a program?


2. Is return statement optional? If return statement is not used inside the function, then
what value will be returned by a function.
3. What is the difference between a parameter and an argument? Which one is called an
Actual parameter and a Formal Parameter? Give a suitable Python code to illustrate
both.
4. Define the following with example:
(i) Default arguments?
(ii) Keyword arguments?
5. What is scope? What is the scope resolving rule of Python?
6. What is the difference between Local and Global variables? Illustrate with an example.
7. What is the difference between sending mutable and immutable datatypes as
parameters to the functions?

8. Write a Python function findmax(x,y,z) to find the maximum of three numbers.

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)

(iv) def check(p=1,q=2):


p=p+q
q=q+1
print(p,q)
check()
check(2,1)
check(3)

(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()

4. Give a command to call a function


def dispMesg():
num=5
print(num+5)
a) dispMesg
b) dispMesg(num)
c) dispMesg()
d) def dispMesg()

5. What is the output of the add() function call


def add(a, b):
return a+5, b+5
result = add(3, 2)
print(result)
a) (8,7)
b) 15
c) 8
d) 7
6. Give the output
def calc(num)
if num%2 == 0:
print(num+5)
else
print(num*5)
calc(7)
a) 7
b) 35
c) 12
d) 0

7. Which of the following function headers is correct?


a) def fun(a = 2, b = 3, c)
b) def fun(a = 2, b, c = 3)
c) def fun(a, b = 2, c = 3)
d) def fun(a, b, c = 3, d)

8. Give the output:


def calc(num)
sum=0
for i in range (1,num,2):
sum=sum+i
print(sum)

calc(5)

a) 5
b) 6
c) 9
d) 4

9. What will be the output of the following Python code?


def func():
return num *5
num = 5
print(func())
a) 25
b) 5
c) error
d) 10
10.What will be the output of the following Python code?
def f1():
global x
x+=1

x=10
f1()
print(x)
a) 11
b) 10
c) error
d) 12

11.What will be the output of the following Python code?


x=100
def f1():
global x
x=90
def f2():
x=80
f1()
f2()
print(x)
a) 100
b) 90
c) error
d) 80

12.What will be the output of the following Python code?

x=100
def f1():
global x
x=90
def f2():
x=80

f1()
f2()
print(x)
a) 100
b) 90
c) error
d) 80

13.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')

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

15.Find and write the output of the following python code:

a=10
def call():
global a
a=15
b=20
print(a)

call()

a) 20
b) 35
c) 15
d) 10

16.Find and write the output of the following python code:


x = 50
def func(x):
x=2
func(x)
print('x =', x)
a) x=50
b) x=2
c) x=100
d) x=52

17.Find and write the output of the following python code:


x = 50
def func():
global x
x=2
func()
print('x=', x)
a) x=50
b) x=2
c) x=100
d) x=52

18.Find and write the output of the following python code:


def calcresult () :
i=9
x=0
while i> 1 :
if (i % 2 == 0):
x = i%2
i = i-1
else :
i = i-2
x=i
print (x**2)

calcresult()
a) 49
b) 25
c) 9
d) 1

19.Find and write the output of the following python code:


def makenew(mystr):
newstr = " "
count = 0
for i in mystr:
if count%2 !=0:
newstr = newstr+str(count)
else:
if i.islower():
newstr = newstr+i.upper()
else:
newstr = newstr+i
count +=1
newstr = newstr+mystr[:1]
print ("The new string is :",newstr)

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

20.Find and write the output of the following python code:


def ChangeList():
L=[]
L1=[]
L2=[]
for i in range (1,10):
L.append(i)
for i in range(10,1,-2):
L1.append(i)
for i in range(len(L1)):
L2.append(L1[i]+L[i])
L2.append(len(L)-len(L1))
print (L2)
ChangeList()

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]

21.Find and write the output of the following python code:


def FindOutput():
L="earn"
X=""
L1=[]
count=1
for i in L:
if i in ['a','e','i','o','u']:
X=X+i.swapcase()
else:
if (count%2!=0):
X=X+str(len(L[:count]))
else:
X=X+i
count=count+1
print(X)
Find Output()
a) Ea3n
b) EA3N
c) EA3n
d) eA3n

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

23.Find and write the output of the following python code:


def power(x, y=2):
r=1
for i in range(y):
r=r*x
return r
print (power(3))
print (power(3, 3))
a) 3
b) 9
c) 6
d) 27

24.What will be the output of the following Python code?


def add (num1, num2):
sum = num1 + num2
sum = add(20,30)
print(sum)
a) 50 b) 0 c) Null d) None
25.Name the statement that sends back a value from a function
a) print
b) input
c) return
d) None

26. def Interest(p , c , t = 2 ,r = 0.09):


return p*t*r
Considering the above defined function which of following function call are legal.
1. Interest(p=1000,c=5)
2. Interest(r=0.05,5000,3)
3. Interest(500,t=2,r=0.05)
4. Interest(c=4,r=0.12,p=5000)

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

28.What is the order of resolving scope of a name in a Python program?


(L: Local namespace, E: Enclosing namespace, B: Built in namespace, G: Global
namespace)

a) BGEL
b) LEGB
c) GEBL
d) LBEG

29.Predict the output of the following code:


def check(n1=1, n2=2):
n1=n1+n2
n2=n2+1
print(n1,n2)
check(3)

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

31.What is the output of the below program?


g=0
def fun1(x,y):
global g
g=x+y
return g
def fun2(m,n):
global g
g=m-n
return g
k=fun1(2,3)
fun2(k,7)
print(g)

a) 2 b) -2 c) 12 d) 5

32.What is the output of the following code snippet?


def displaylist(lst):
for i in range(0,len(lst)):
if lst[i]%2 == 1:
lst[i]* = 5
L = [5 , 4, 7 , 8]
displaylist(L)
for i in L:
print(i, end="@")

a) 5@4@7@8@
b) 25@4@35@8@
c) 25@20@35@40@
d) 5@20@7@40

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy