+ 1
Help (Halloween Candy)
houses = int(input()) #your code goes here porcentaje = round ((2 / houses)*100) print (porcentaje) This is my code in Python, it is accepted by the first two test cases, but the hidden cases give errors. Please help
5 Answers
+ 3
đNBđ Rain thanks, I think I understood, round() to round to the nearest integer and math.ceil() to round up
+ 1
Dayana Alvarez ,
Yeah, you have to round up, not round to the nearest.
+ 1
Here's my code, not need to import modules.
houses = int(input())
dollar_p = (2 / houses) * 100
rounded = dollar_p if dollar_p == int(dollar_p) else dollar_p + 1
if houses >= 3:
print(int(rounded))
The rounded part check if dollar_p is an interger, if it's not it add +1 to dollar_p...
In the print function, I added "int" to make the float and integer and essentially rounding up the result.
It could be improved by making sure rounded is always an integer in the assignment of "rounded" but this works perfectly.
0
It worked adding 0.5, although I didn't understand much. For example, if there are 15 houses, the result is 14, but before rounding it is 13.333333 which is closer to 13. I thought the round() function was responsible for rounding to the nearest integer