Q:

Write a program in Python to calculate the value of the following expression by using lambda function

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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: 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)
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

total answers (1)

Python Exercises, Practice Questions and Solutions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a program in Python to calculate the Fahrenh... >>
<< Write a program in Python to keep count of this gi...