- 1
Module 2 quiz
Hi guys, i need help. I have task: "fill in the blanks to colculate the expression x*(x+1) using an anonymous function and call it for the number 6". And i think, that's true answer is: " a = (lambda x: x*(x+1)) a(6) print(a) " But it is wrong and i don't understand why. Please help, if you can
4 Réponses
+ 2
You should print the value of a(6) not a itself because a contains the object of that function.
try this:
print(a(6))
+ 1
No, it is does not work, cos in these place i couldn't redacted. No, i am already done it. It looks like:
a=(lambda x:x*(x+1))(6)
print(a)
+ 1
a = (lambda x: x*(x+1))
print(a(7))
a = (lambda x: x*(x+1))(7)
print(a)
Both works same. But 2nd one only working for argument 7. While 1st one works for any number
You can update 2nd one same as 1st like
x=int(input())
a = (lambda x: x*(x+1))(x)
#or
#a = (lambda x: x*(x+1))(int(input()))
print(a)
0
The way the code is displayed on the question is really misleading:
It should be displayed as:
a = (BLANK x: x BLANK (x+1))(BLANK)
print(a)
From this it is easier to see you only need 2 rows