1 Crore+ students have signed up on EduRev. Have you? Download the App |
What will be the output of the following code?
def multiply(a, b):
return a * b
result = multiply(4, 5)
print(result)
What will be the output of the following code?
def greet(name):
print("Hello, " + name + "!")
greet("Alice")
What will be the output of the following code?
def calculate_average(numbers):
total = sum(numbers)
avg = total / len(numbers)
return avg
scores = [85, 90, 92, 88, 95]
average_score = calculate_average(scores)
print(average_score)
What will be the output of the following code?
def greet():
message = "Hello, world!"
print(message)
greet()
print(message)
What will be the output of the following code?
def power(base, exponent=2):
return base ** exponent
result1 = power(3)
result2 = power(2, 4)
result3 = power(exponent=3, base=5)
print(result1, result2, result3)
What will be the output of the following code?
x = 5
def update_global():
global x
x = 10
update_global()
print(x)
What will be the output of the following code?
def outer_function(x):
def inner_function(y):
nonlocal x
x += y
return x
return inner_function
add_5 = outer_function(5)
result = add_5(3)
print(result)
What will be the output of the following code?
def function_with_args(*args):
return len(args)
result = function_with_args(1, 2, 3, 4, 5)
print(result)
What will be the output of the following code?
def function_with_kwargs(**kwargs):
return kwargs
result = function_with_kwargs(a=1, b=2, c=3)
print(result)
What will be the output of the following code?
def calculate_total(*numbers):
total = 0
for num in numbers:
total += num
return total
result = calculate_total(1, 2, 3, 4)
print(result)