+ 1

Lambdas - Python Developer

I am working through the Python Developer course and am currently on the section about lambdas. I attempted this code coach but keep failing a hidden test case. What am I doing wrong? https://code.sololearn.com/cfltk1CJCmxL/?ref=app

11th Aug 2023, 2:23 PM
Lashana Jegatheswaran
4 odpowiedzi
+ 7
Lashana Jegatheswaran , the code and the formula you have applied is correct, but it can create an unexcepted output. > x/100*y the reason is that you first divide x by 100, then multiply it by y. > x*y/100 this version will work > the reason for this is the float precision issue. # your version: x = 69 y = 13 result = 8.969999999999999 # suggested version: x = 69 y = 13 result = 8.97 the preferred version is: ... res = (lambda x,y:x*y/100)(price, perc) ...
11th Aug 2023, 9:05 PM
Lothar
Lothar - avatar
+ 3
Hmm.. Try changing the order of x and y to this.. https://code.sololearn.com/cqLQhJCkN63t/?ref=app I tried your code order with input 10 and 3 for price and perc, respectively and it gives me 0.300000...4, while my order gives 0.3. This is because the computer have its own "definition" for floating point numbers. It has its own way to perform operations with floating point numbers, so yeah.. If you are interested in, you can search up for it.
11th Aug 2023, 3:00 PM
Dragon RB
Dragon RB - avatar
+ 1
Thank you all so much!
12th Aug 2023, 2:09 AM
Lashana Jegatheswaran
0
These are the instructions for the code: 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
11th Aug 2023, 2:23 PM
Lashana Jegatheswaran