Function WS
Function WS
a) 10
b) 30
c) error
d) 20
2. Name the Python Library modules which need to be imported to invoke the
following functions:
a) sin()
b) randint()
35 | P a g e
8. The values being passed through a function call statements are called
a) Actual parameter
b) Formal parameter
c) default parameter
d) None of these
a) global a
b) global b=100
c) global b
d) global a=100
36 | P a g e
a) 5
b) 6
c) 4
d) This code will raise an error.
14. A function is defined as below, the function call parameters can be:
a) Two tuples
b) Two numbers
c) One number
d) All of the above
16. What possible outputs(s) are expected to be displayed on screen at the time of
execution of the program from the following code? Also specify the maximum
values that can be assigned to each of the variables Lower and Upper.
a) 10#40#70#
b) 30#40#50#
c) 50#60#70#
d) 40#50#70#
17. What will be the output of the Python code?
>>> def testify(a,b):
return a-b
>>> sum=testify(22,55)
>>> sum+30
a) 33
b) -33
c) 3
37 | P a g e
d) -3
21. Look at the function definition and the function call and determine the correct
output
>>> def test(a):
if(a>10):
a += 10
if(a>20):
a += 20
if(a>30):
38 | P a g e
a +=30
print(a)
>>> test(11)
a) 21
b) 72
c) 61
d) 71
a) [1, 2, 3, 4, 5, 6]
b) [100, 2, 3, 4, 5, 6]
c) [100, 2, 3, 4, 5]
d) [1, 2, 3, 4, 5]
a) [1, 2, 3, 4]
b) [5, 6, 7]
c) [1, 2, 3, 4, 5, 6, 7]
d) This code will raise an error.
24. Assertion (A): To use a function from a particular module, we need to import
the module.
Reason (R): import statement can be written anywhere in the program,
before using a function from that module.
a) Both A and R are true and R is the correct explanation for A
b) Both A and R are true and R is not the correct explanation for A
c) A is True but R is False
d) A is false but R is True
39 | P a g e
25. What will be the output of the following Python code?
def add (num1, num2):
sum = num1 + num2
sum = add(20,30)
print(sum)
27. What possible outputs(s) are expected to be displayed on screen at the time of
execution of the program from the following code? Also specify the maximum
values that can be assigned to each of the variables FROM and TO.
a) 10#40#70#
b) 30#40#50#
c) 50#60#70#
d) 40#50#70#
40 | P a g e
29. Predict output:
30. Rewrite the following code after removing the syntactical errors (if any).
Underline each correction.
a) Delhi#Mumbai#Chennai#Kolkata#
b) Mumbai#Chennai#Kolkata#Mumbai#
c) Mumbai# Mumbai #Mumbai # Delhi#
d) Mumbai# Mumbai #Chennai # Mumbai
41 | P a g e
34. What will be the output of the following code?
i. ii.
37. Find and write the output of the following Python code:
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"#" print(m)
42 | P a g e
Display('[email protected]')
38. Find and write the output of the following python code:
I ii
39. What are the possible outcome/(s) for the following code.Also specify the
maximum and minimum value of R when K is assigned value as 2:
a) Stop # Wait # Go
b) Wait # Stop #
c) Go # Wait #
d) Go # Stop #
43 | P a g e
41. Explain the positional parameters in Python function with the help of
suitable example.
42. Predict the output of following:
i. ii.
iii. iv.
v vi
44. What possible outputs(s) will be obtained when the following code is
executed?
Options:
a) RED* b) WHITE*
WHITE* BLACK*
BLACK*
c) WHITE* WHITE* d) YELLOW*
BLACK* BLACK* WHITE*WHITE*
BLACK* BLACK* BLACK*
44 | P a g e
45. What possible outputs(s) are expected to be displayed on screen at the time
of execution of the program from the following code? Also specify the
maximum values that can be assigned to each of the variables BEGIN and END.
a) 60#35#
b) 60#35#70#50#
c) 35#70#50#
d) 40#55#60#
46. What possible outputs(s) are expected to be displayed on screen at the time of
execution of the program from the following code? Also specify the maximum
values that can be assigned to each of the variables Lower and Upper.
a) 10#40#70#
b) 30#40#50#
c) 50#60#70#
d) 40#50#70#
47. What are the possible outcome/s for the following code:
Options:
a) 34:31:30:33:
b) 29:33:30:31:
c) 34:31:30:31:
d) 34:31:29:33:
45 | P a g e
48. What are the possible outcome/s :
1 Guess=65
for I in range(1,5):
New=Guess+random.randint(0,I)
print(chr(New),end=' ')
Output Options:
a) A B B C
b) A C B A
c) B C D A
d) C A B D
Output Options :
a) 25
b) 34
c) 20
d) None of the above
Output Options :
a) 99
b) 94
c) 96
d) None of the above
4 Disp=22
Rnd=random.randint(0,Disp)+15
N=1
for I in range(3,Rnd,4):
print(N,end=" ")
N+=1
print()
Output Options:
a) 1
b) 1 2 3 4
c) 1 2
d) 1 2 3
46 | P a g e
5 Area=["NORTH","SOUTH","EAST","WEST"]
for I in range(3):
ToGo=random.randint(0,1) + 1
print(Area[ToGo],end=":")
print()
Output Options:
a) SOUTH : EAST : SOUTH :
b) NORTH : SOUTH : EAST :
c) SOUTH : EAST : WEST :
d) SOUTH : EAST : EAST :
6 MIN = 25
SCORE = 10
for i in range (1,5):
Num = MIN + random.randint(0,SCORE)
print(Num,end=":")
SCORE-=1;
print()
Output Options:
a) 34:31:30:33:
b) 29:33:30:31:
c) 34:31:30:31:
d) 34:31:29:33:
49. Ms. Sana wants to increase the value of variable x by 1 through function
modify(). However this code raises error .Help sana to rectify the code:
i. ii.
47 | P a g e
iii. iv.
i. ii.
iii. iv.
48 | P a g e
54. Predict output:
i. ii.
iii. iv.
Practical Exercise
1 Write a Python function named `calculate_gross_salary` that takes the
basic salary (an integer) as an argument and returns the gross salary. The
gross salary is calculated as follows:
- If the basic salary is less than or equal to 10000, the gross salary
is the basic salary plus 20% of the basic salary.
- If the basic salary is more than 10000, the gross salary is the
basic salary plus 25% of the basic salary.
Write the function definition for `calculate_gross_salary` and use
it to calculate the gross salary for a basic salary of 12000.
2 Write a Python function called calculate_average that takes a list of
numbers as input and returns the average of those numbers.
3 Write a function update_list(L) that receives a list as arguments and
increases the value of even elements by 2.
For example: if the list is [2,4,6,7,9]
after execution of function, the list should be : [4,6,8,7,9]
49 | P a g e