Adding Three Numbers Using Lambda

Write a Python program that uses a lambda function to add three given numbers. The function should return the sum.

Example 1:

Input: 1, 2, 3 
Output: 6

Example 2:

Input: 10, 20, 30 
Output: 60

Use a lambda function to create an anonymous function that adds three numbers.

# Define the lambda function
add_three_numbers = lambda x, y, z: x + y + z

# Test the function
print(add_three_numbers(1, 2, 3)) # Output: 6
print(add_three_numbers(10, 20, 30)) # Output: 60

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!