+ 4

Why doesn’t my code work?

https://sololearn.com/coach/4/?ref=app (Halloween Candy challenge) Can someone please tell me why my solution is not right? I can’t see the solutions that don’t work. EDIT: Thank you for the answers, I understand now why it wasn’t good. (Though I thought the challenge instructions weren’t clear) Leaving this post up in case others have the same problem.

28th Jul 2022, 5:28 PM
alepou
alepou - avatar
5 ответов
+ 6
alepou the reason why your code is not correct is because you are rounding either up or down to the closes int, while the challenge wants you to round up. In other words, if you had 20.10 % chance of getting a dollar, you would have to round it up to 21
28th Jul 2022, 6:30 PM
YuGiMob
YuGiMob - avatar
+ 6
alepou , as already mentioned we have to round the result of the calculation UP. this can be done with the ceil() function. to use it, we have to import the math module.
28th Jul 2022, 7:51 PM
Lothar
Lothar - avatar
+ 3
# Hi, alepou ! # You can compare your code with this one: ch = 2/int(input()) * 100 print(int(ch + 1 if ch > int(ch) else ch))
28th Jul 2022, 6:13 PM
Per Bratthammar
Per Bratthammar - avatar
28th Jul 2022, 5:40 PM
alepou
alepou - avatar
0
YuGiMob thank you!
28th Jul 2022, 7:33 PM
alepou
alepou - avatar