Competency Based Worksheet 02 on Python Functions
Competency Based Worksheet 02 on Python Functions
Python Functions
1 The function which is defined by programmer and not available already in program is : 1
hello("Anjali")
3 Which of the following function calls is incorrect if the function is defined as: 1
a. calculate(1) b. calculate(1, 4)
c. calculate(1, c=4) d. calculate(b=3, 1, c=2)
def greet():
name = "Python"
return name
print(greet())
A function must always be called with all parameters provided, even if some have default
values.
The keyword return is used to send a value back to the function caller.
13 Assertion (A) : Importing a module with * makes the size of the program bigger. 1
Reason (R) : Python interpreter imports the module function code in the program before
execution.
14 Assertion (A) : In a Python function call, you can mix positional and keyword arguments. 1
Reason (R) : Python allows keyword arguments to be passed before positional arguments.
15 Assertion (A) : Default arguments in a function must be placed after all non-default 1
arguments.
Reason (R) : Python uses left-to-right evaluation for function arguments.
18 Rewrite the following code in python after removing all syntax error(s). Underline each 2
correction done in the code.
DEF calculate_sum(numbers)
sum = 0
for number in numbers:
sum = number
return Sum
19 Rewrite the following code in python after removing all syntax error(s). Underline each 2
correction done in the code.
def greet(name)
message = "Hello, " + name
return message
def farewell(name):
return "Goodbye " + name
print(greet(123)
print(farewell(456)
greet("John"
show("Ravi")
display(age=20, "Karan")
22 The following python code contains error(s). Rewrite the correct code and underline the 2
corrections made by you
23 The following python code contains error(s). Rewrite the correct code and underline the 2
corrections made by you
DEF test ( ) :
x=x+1
return x
print(x)
test ( )
print(calculate_total(100))
print(calculate_total(100, 2))
print(calculate_total(100, 2, 10))
def wrapper():
print(combine("Hello", "World"))
print(combine("Python", "Programming", sep=" - "))
print(combine(10, 20, sep=":"))
wrapper()
info("Nina", city="Mumbai")
func(3, z=20)
x = 10
def show():
x=5
print(x)
show()
print(x)
print(multiply(3))