0% found this document useful (0 votes)
6 views2 pages

10_assignment_

The document contains a series of programming questions and answers related to Python functions and lambda expressions. It includes examples of lambda functions for summing numbers, calculating area, factorial, and finding maximum values, as well as functions for checking voter eligibility and counting numbers in specified ranges. Each function demonstrates the use of arbitrary arguments and keyword arguments.

Uploaded by

sainikaustubh4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

10_assignment_

The document contains a series of programming questions and answers related to Python functions and lambda expressions. It includes examples of lambda functions for summing numbers, calculating area, factorial, and finding maximum values, as well as functions for checking voter eligibility and counting numbers in specified ranges. Each function demonstrates the use of arbitrary arguments and keyword arguments.

Uploaded by

sainikaustubh4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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: math.pi * 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 details.get('age', 0) >= 18:
return f"{details.get('name', 'Person')} is eligible to vote."
else:
return f"{details.get('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

You might also like