0

Doubts in solving Halloween Candy problem

Hello! I'm facing this problem. It's Halloween and someone has visited N number of houses. We know 3 of N houses are giving random objects: one is giving toothbrushes and two others are giving money (something like this, cannot remember exactly). So, I'm asked to write a code in which, given an N number as an input where N >= 3, it found the rounded percentage of getting money. I solved like follows, houses = int(input()) if houses >= 3: print(round((2*100)/houses)) else: print('Please, visit more houses!') So, it works fine with the two first cases, but it's failing in the rest. And, as I cannot see this rest, I have no clue and cannot figure out where is the mistake. So I've decided to kindly ask for help. Thanks and regards! PS: It's written in python

19th Nov 2021, 5:15 PM
Bárbara L. V.
Bárbara L. V. - avatar
4 odpowiedzi
+ 3
You need to use ceil instead of round function. Try this: https://code.sololearn.com/c33sxtJKX8HG/?ref=app
19th Nov 2021, 5:42 PM
Lebi
+ 2
Carefully reread the task description. Two hints: - What exactly does it say about rounding? - What does it tell you to do if there are less than three houses?
19th Nov 2021, 5:36 PM
Simon Sauter
Simon Sauter - avatar
+ 2
The number of houses is always >= 3. And you have to round up
19th Nov 2021, 5:37 PM
Paul
Paul - avatar
+ 1
Now I see. As a new I did not know the ceil function! Thanks everyone for your help!
20th Nov 2021, 10:10 PM
Bárbara L. V.
Bárbara L. V. - avatar