+ 2

Python Lambda Practice

I am going through Lambda lesson practice of Python Intermediate and when I write and run the code one case is not passing correctly (Case 4). Please check and provide feedback 😊 This is my code snippet: price = int(input()) perc = int(input()) res = (lambda x,y: (x/100)*y)(price, perc) print(res)

21st Dec 2023, 9:33 AM
Wakil Ah Hamidi
Wakil Ah Hamidi - avatar
5 odpowiedzi
+ 1
x * y / 100 Try this
21st Dec 2023, 9:40 AM
A͢J
A͢J - avatar
+ 5
A͢J , in python 99 / 100 will result in 0.99, but not in 0 as you mentioned in your last answer.
23rd Dec 2023, 7:10 AM
Lothar
Lothar - avatar
0
Yeah it is working, but may I know why my approach is not working 100%
21st Dec 2023, 9:45 AM
Wakil Ah Hamidi
Wakil Ah Hamidi - avatar
0
Try this: price = 80 perc = 7 res_1 = (lambda x,y: (x/100)*y)(price, perc) # your solution res_2 = (lambda x,y: x * y / 100)(price, perc) # AJ solution print('Your solution:', res_1, '\nAJ solution:', res_2)
21st Dec 2023, 10:33 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
Wakil Ahmad Hamidi Because 99 / 100 would be 0 so 0 * 10 = 0 but 99 * 10 / 100 would be 9.9
21st Dec 2023, 6:34 PM
A͢J
A͢J - avatar