0
Trying to solve Code Coach Challenge "Halloween Candy"
The problem involves you and friend trick or treating, all houses give candy except for 3, which one gibes out toothbrushes, and two give out $1 bills. You are to calculate the chances of you getting a $1 bill given an input total number of houses viaited that night. They gave the example of 4 total houaes would output 50, i.e. of the 4 houses 1 would give candy, 1 toothbrushes, 2 $1 bills. That becomes 2 out of 4, which comes out to 50(percent) I input this code: houses = int(input()) print(round((2/houses)*100)) It passes test 1 and test 2 but fails the other tests, which are locked. The problem seems simple enough. I need someone to show me the error of my ways on this. Thanks
4 ответов
+ 2
You need to round up.
import math
# and use
math.ceil(....)
+ 1
ChaoticDawg Thanks. It worked.
0
I thought "round" rounded up. I will try "ceil". Thanks.
0
Forgot to respond back to this post. My apologies. "math.ceil" worked. Thanks.