bake_time = lambda time: 40 - time is wrong? in python

The issue with the lambda function bake_time = lambda time: 40 - time is not that it is wrong, but rather that it is subtracting time from 40 instead of adding time to 40.

If you want to add time to 40 using a lambda function, you can modify it like this:

main.py
bake_time = lambda time: 40 + time
35 chars
2 lines

Now, if you pass a value to bake_time, it will add that value to 40 and return the result.

For example:

main.py
print(bake_time(10))  # Output: 50
35 chars
2 lines

Here, bake_time(10) will return 50 because 40 + 10 equals 50.

Remember that lambda functions are anonymous functions, so you can assign them to variables and use them wherever you need them.

Note: It's important to ensure that you are using the appropriate arithmetic operator (+ for addition, - for subtraction) based on your desired outcome.

related categories

gistlibby LogSnag