+ 3

Help me debug programm

I need count percent using lambda function. One test failed. I dont understand why? price = int(input()) perc = int(input()) res = (lambda x,y:(x/100)*y) print(res(price, perc))

4th Dec 2023, 7:53 PM
Olga Belyavskaya
Olga Belyavskaya - avatar
7 Answers
+ 8
Olga Belyavskaya , ok, i think the reason for the issue is that `x` and `y` are mixed up in the formula. should be: ... res = (lambda x,y:(y/100)*x) ...
4th Dec 2023, 8:26 PM
Lothar
Lothar - avatar
+ 7
Olga Belyavskaya , > can you give a short sample of the 2 input values, as well as the expected result? > also give a short description.
4th Dec 2023, 8:17 PM
Lothar
Lothar - avatar
+ 5
price = 100 percent = 7 res = (lambda x, y: (x / 100) * y) print(res(price, percent)) #7.0 res2 = (lambda x, y: (y / 100) * x) print(res2(price, percent)) #7.000000000000001 res3 = (lambda x, y: (x * y) / 100) print(res3(price, percent)) #7.0 The lambda takes 2 arguments, the first is x, and second is y. When you try to print it, you provide it with two argument, the first is price, and second is percent. Therefore x becomes price, and y becomes percent. If you provide the arguments in different order: first is percent, second is price, x will become percent and y will become price.
5th Dec 2023, 1:52 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 3
It is work! Thank you. Can you explain me please 'x' its price and 'y' its perc? So why we must 'perc' \\ 100?
4th Dec 2023, 9:30 PM
Olga Belyavskaya
Olga Belyavskaya - avatar
+ 1
What are variables x & y? Should they be price & perc? [edit: turns out I don't know how to use lambda.... woops]
4th Dec 2023, 8:19 PM
HungryTradie
HungryTradie - avatar
0
10000
6th Dec 2023, 4:07 PM
Kadir Abdalla
0
Tira
6th Dec 2023, 7:39 PM
Juliomendes Guimares neto
Juliomendes Guimares neto - avatar