- 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

22nd Jun 2021, 5:17 PM
Andrey Zinin
4 odpowiedzi
+ 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))
22nd Jun 2021, 5:25 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 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)
22nd Jun 2021, 5:29 PM
Andrey Zinin
+ 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)
22nd Jun 2021, 5:49 PM
Jayakrishna 🇮🇳
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
5th Jun 2023, 9:16 AM
james tweddle