+ 2
[✔️]what is the solution of this problem ? i stuck on this code coach. please help me. i complete all the test cases accept 4th.
LAMBDA You are given code that should calculate the corresponding percentage of a price. Somebody wrote a lambda function to accomplish that, however the lambda is wrong. Fix the code to output the given percentage of the price. Sample Input 50 10 Sample Output 5.0 ⚠️ The first input is the price, while the second input is the percentage we need to calculate: 10% of 50 is 5.0. #my code is: price = int(input()) perc = int(input()) print ( float( (lambda x,y:x / 100 * y) (price, perc) ) )
5 Réponses
+ 6
#...._._...._<........>
i am quite sure that the issue is with the sequence of the operators and the values. in ideal case there is no issue, but since we are using float numbers there is a difference. this is not incorrect what you have done, and it is also no bug, it is just as it is.
using these values:
=> price: 7
=> percent: 10
the result is different depending like mentioned abouve:
your lambda: (lambda x, y: x / 100 * y) :
7
10
result: 0.7000000000000001
modified lambda: (lambda x,y:x*y/100) :
7
10
result: 0.7
+ 4
#...._._...._<........>
I ran your code and it seems fine, so I would suggest to look at rounding to 2 places.
For example 10 with a 30 discount will produce 3.333333333
But, when talking money, 2 decimal places are expected -> 3.33
I don't know if this will resolve the problem, but without access to your challenge details, I can only surmise
+ 4
Rik Wittkopp ,
you are right, rounding with round(..., 2) will pass the test cases also
+ 3
Lothar ,
yeah!
you are right.
your modified lambda is right; with that modification i successfully passed all the test cases.🤩😄
+ 3
Lothar
&
Rik Wittkopp ,
😃🙏Thank you so much both of you..🎊👏🙌