+ 2

Halloween Candy Problem

Hello, all. I tried to make it without import Math, however, I am stuck. Could you tell me what is the problem? houses = int(input()) before_round = ((2/houses)*100) remain=before_round%1 if remain<0.5: pass else: before_round+=1 print(round(before_round))

13th Mar 2022, 1:51 AM
Earl
Earl - avatar
10 Respuestas
+ 3
Try this, (should work): houses = int(input()) before_round = 2/houses*100 remain=before_round%1 if 0!=remain<0.5: before_round+=1 print(round(before_round)) Although there is a much shorter way 😉
13th Mar 2022, 3:52 AM
Solo
Solo - avatar
+ 4
Earl , there is nothing to be confused about, it is only important to know that there are different ways of rounding and they must be taken into account when compiling programs.☺️
15th Mar 2022, 2:15 AM
Solo
Solo - avatar
+ 3
You can round up without the math module, but why do it if you don't have to? https://code.sololearn.com/cmRYOBX43VRO/?ref=app
13th Mar 2022, 3:04 AM
Simon Sauter
Simon Sauter - avatar
+ 3
Earl, the assignment clearly states that the output should be rounded to the nearest whole number, so "ceil" has absolutely nothing to do with it.
15th Mar 2022, 1:23 AM
Solo
Solo - avatar
+ 2
# Hi! You can try this: ch = 2/int(input()) * 100 print(int(ch + 1 if ch > int(ch) else ch))
13th Mar 2022, 8:04 AM
Per Bratthammar
Per Bratthammar - avatar
+ 2
Simon Sauter 😳 Seriously? Are you sure?🤔
15th Mar 2022, 1:57 AM
Solo
Solo - avatar
+ 1
Solo rounded *up*: "Output Format A percentage value rounded up to the nearest whole number."
15th Mar 2022, 1:33 AM
Simon Sauter
Simon Sauter - avatar
0
Thank you all! Yeah I think I need to use ceil...
14th Mar 2022, 12:09 PM
Earl
Earl - avatar
0
I copied and pasted it directly from the description. Admittedly, saying both "rounded up" and "nearest whole number" is somewhat unfortunate and potentially confusing.
15th Mar 2022, 2:00 AM
Simon Sauter
Simon Sauter - avatar
0
Sorry, I was confused too. The output should be 'rounded up' 🤣
15th Mar 2022, 2:02 AM
Earl
Earl - avatar