Write a program in Python to calculate the value of the following expression by using lambda function
The expression is -
(x * 10) + (y / 2) * z
Lambda is an anonymous function that contains any number of arguments, but only one expression. This function is defined without a name.
lambda arguments: expression
Here, the arguments can be any numbers, but the expression should be only one.
This is the following solution to calculate the value of the given expression by using lambda function.
print("Please enter the values of x, y and z") x = input() y = input() z = input() expr = lambda x, y, z: (x * 10) + (y / 2) * z print expr(x, y, z)
Please enter the values of x, y and z
10
2
20
120
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Solution
Lambda is an anonymous function that contains any number of arguments, but only one expression. This function is defined without a name.
Syntax of Python lambda()
lambda arguments: expressionHere, the arguments can be any numbers, but the expression should be only one.
This is the following solution to calculate the value of the given expression by using lambda function.
Output of the above code
Please enter the values of x, y and z
10
2
20
120
need an explanation for this answer? contact us directly to get an explanation for this answer