+ 1

Code couch: Halloween candy

I don't know what I'm missing here: houses = int(input()) total_items = houses num_dollar_bills = 2 #your code goes here percentage = (num_dollar_bills / total_items) * 100 rounded_percentage = round(percentage) print(rounded_percentage) I passed the test case 1 and 2 but 3, 4 and 5 don't work they are hidden so I'm not sure what I did wrong

27th Mar 2024, 2:27 PM
Jordan
5 Respuestas
+ 3
houses = int(input()) #your code goes here a = 2/houses b = a * 100 c = int(b) if c == b: print (c) else: print (c + 1) here you go :) a valid and easier code
27th Mar 2024, 7:34 PM
thata 𖹭
thata 𖹭 - avatar
+ 6
[sp.: Dode couch = Code Coach] Jordan it seems that you missed a small detail in the requirements. Output Format A percentage value rounded *up* to the nearest whole number. Your code is only rounding. To round up, use the ceil() function.
27th Mar 2024, 3:02 PM
Brian
Brian - avatar
+ 4
Jordan you could implement your own ceil function. Here is one way that I tried successfully with Code Coach: def ceil(a): return int(a)+(a>int(a)) Although there is a simpler way. Just add 0.5 before rounding: rounded_percentage = round(percentage + 0.5) This passes all the tests as well. I should mention, though, that this latter technique is not a general way to make a ceil function. There is an edge case where it may give a different result. That is, if percentage is an odd whole number, then round with added 0.5 would bump it up to the next whole number. The ceil function I gave does it better.
27th Mar 2024, 8:34 PM
Brian
Brian - avatar
+ 2
Brian thank you I didn't noticed the "round UP" 🙃 CODE UPDATE import math houses = int(input()) total_items = houses num_dollar_bills = 2 #your code goes here percentage = (num_dollar_bills / total_items) * 100 rounded_percentage = math.ceil(percentage) print(rounded_percentage) is there a way to do this code without the import?
27th Mar 2024, 6:30 PM
Jordan
+ 1
thata 𖹭 thank you Your code is way simpler then mine
28th Mar 2024, 1:15 PM
Jordan