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

5th Aug 2021, 9:37 PM
Robert Haugland
Robert Haugland - avatar
4 odpowiedzi
+ 2
You need to round up. import math # and use math.ceil(....)
5th Aug 2021, 10:55 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg Thanks. It worked.
6th Aug 2021, 7:53 AM
Robert Haugland
Robert Haugland - avatar
0
I thought "round" rounded up. I will try "ceil". Thanks.
6th Aug 2021, 7:51 AM
Robert Haugland
Robert Haugland - avatar
0
Forgot to respond back to this post. My apologies. "math.ceil" worked. Thanks.
13th Sep 2021, 6:12 PM
Robert Haugland
Robert Haugland - avatar