Q.
1 Multiple Choice
1. c. Partial Argument
2. d. Allows mutable values only as argument.
3. d. Allows any type of value as argument.
4. d. Default argument allows non-default argument to follow default.
5. b. It cannot access global namespace variables.
Q.2 Lambda Function to Find Sum of 4 Numbers
sum_of_4_numbers = lambda a, b, c, d: a + b + c + d
Q.3 Lambda Function to Calculate Area of Circle
import math
area_of_circle = lambda radius: [Link] * radius * radius
Q.4 Lambda Function to Calculate Factorial of a Number
factorial = lambda n: 1 if n == 0 else n * factorial(n - 1)
Q.5 Lambda Function to Find Maximum from List
max_from_list = lambda lst: max(lst)
Q.6 Function to Find Maximum from Numbers Passed as Argument (Using Arbitrary
Argument)
def max_from_numbers(*args):
return max(args)
Q.7 Function to Find the Person Eligible to Vote (Using Arbitrary Keyword Argument)
def check_voter_eligibility(**details):
if [Link]('age', 0) >= 18:
return f"{[Link]('name', 'Person')} is eligible to vote."
else:
return f"{[Link]('name', 'Person')} is not eligible to vote."
Q.8 Function to Find Sum of Numeric Arguments (Using Arbitrary Argument)
def sum_numeric_values(*args):
return sum(arg for arg in args if isinstance(arg, (int, float)))
Q.9 Function to Count Numbers in Specified Ranges
def count_numbers_in_ranges(*args):
counts = {'< 0': 0, '0 - 50': 0, '51 - 100': 0, '> 100': 0}
for num in args:
if num < 0:
counts['< 0'] += 1
elif 0 <= num <= 50:
counts['0 - 50'] += 1
elif 51 <= num <= 100:
counts['51 - 100'] += 1
else:
counts['> 100'] += 1
return counts