+ 1

Lambdas challenge "How much?" in python

"How Much? Fix the code to output the percentage of the price. 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" here is what I have: /// price = int(input(" ")) perc = int(input(" ")) res = (lambda x,y: y * (x/100))(price, perc) round(res, 2) print(res) /// I can get all the cases correctly except for test case 4. Test case 4 is locked. When I use print("%.1f" % res) to round the decimal point to 1, test case 4 is correct, but test case 1 is then incorrect, since it rounds 53.76 to 53.8, now giving the incorrect output. Anyone here know how to fix the issue where it seems one answer needs two decimal places and another needs one? Thanks in advance, looking forward to figuring this out!

22nd Jun 2021, 1:58 PM
mikielmcrae
5 Respostas
+ 5
round function return result: it does not modify the argument ^^ either do: res = round(res,2) or: res = round((lambda ...)(price,perc),2) or: print(round(res,2))
22nd Jun 2021, 2:04 PM
visph
visph - avatar
+ 6
mikielmcrae true words😉
22nd Jun 2021, 2:14 PM
Oma Falk
Oma Falk - avatar
+ 4
You figured it out! Thanks so much! It's always a simple fix right in front of your face hahaha
22nd Jun 2021, 2:06 PM
mikielmcrae
+ 4
my solution: price = int(input()) perc = int(input()) res = (lambda x,y: (x*y)/100) (price, perc) print(res)
19th Dec 2022, 12:27 PM
Alessandro Rho
Alessandro Rho - avatar
+ 1
price = int(input()) perc = int(input()) res = (lambda x,y:x*y/100)(price, perc) print(res) #this code is working #you need to solve the easy math #if 50*10/100 #just you need change this part x*y/100
10th Oct 2023, 5:21 AM
Sharareh.H
Sharareh.H - avatar