Помогите с решением задачи | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Помогите с решением задачи

Задание на питоне ,нужно рассчитать процент от суммы (сумма /100) * процент с помощью лямбда функции но одно из скрытых заданий не поддаётся мне price = int(input()) perc = int(input()) print((lambda x,y:(x/100)*y)(price, perc))

8th Oct 2023, 2:09 AM
Егор Артюшкин
Егор Артюшкин - avatar
9 Respuestas
+ 1
Опишите полностью задание. Я могу лишь предположить что у Вас не правильно написана формула. Я бы написал так: x*y/100
8th Oct 2023, 5:37 PM
Solo
Solo - avatar
+ 2
The case is hidden so I cannot be sure, but moving around the formula does pass all cases. My best guess is how computer handle float in a way than humans do. Try to do the division in the last step and see anything is changed.
8th Oct 2023, 4:38 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Спасибо solo ,реально ошибка в формуле была
8th Oct 2023, 6:28 PM
Егор Артюшкин
Егор Артюшкин - avatar
+ 1
Wong Hei Ming , thanks for the answer, there was an error in the formula
8th Oct 2023, 6:29 PM
Егор Артюшкин
Егор Артюшкин - avatar
+ 1
Егор Артюшкин, если Вы хотите обратиться к кому-нибудь персонально, то кликните на @ и у Вас всплывёт список имён, после выбора имя будет написано зелёным цветом и пользователю прийдёт уведомление о том что его упомянули... 🖐️😎
8th Oct 2023, 8:24 PM
Solo
Solo - avatar
+ 1
Егор Артюшкин, there is nothing wrong in your formula in terms of mathematical logic. The problem is how computer handle floating point number. Try below code in code playground print((82/100)*7) # 5.739999999999999 print(82*7/100) # 5.74 Computer stores information in binary code (0 and 1), it cannot precisely store floating point number in 10 base like we normally do. There are modules to handle this kind of problem. You can search for 'python decimal' to learn more.
9th Oct 2023, 2:18 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
Wong Hei Ming got it, thanks for the help
9th Oct 2023, 7:59 AM
Егор Артюшкин
Егор Артюшкин - avatar
0
Wong Hei Ming, just the same, from the point of view of mathematical logic, a mistake was made, because programmers, when creating a compiler, adhered to mathematical laws. In this example, we are not just talking about calculating individual numbers, 82, 100, 7, and determining the percentage ratio, that is, it is necessary to multiply 82 by 7 parts of 100%. seven hundredths is a fractional number and should be written either 7/100 or 0.07 and now you can at least multiply 82 by seven hundredths, at least multiply seven hundredths by 82 the result will be the same 5.74: 82*0.07 or 7/100*82 etc. not 82/100*7
9th Oct 2023, 9:44 AM
Solo
Solo - avatar
0
It's beautiful
9th Oct 2023, 11:33 AM
MHMAD FAHIM
MHMAD FAHIM - avatar