+ 1

Halloween Candy — Challenge — Help

I'm doing Halloween Candy code coach challenge. Once again, I have passed tests 1 and 2. But I don't seem to pass any other tests within that challenge. This is my code: https://code.sololearn.com/cRq7WmfzaAOg/?ref=app Any guidance?

27th Dec 2022, 7:14 PM
Lamron
Lamron - avatar
7 Respostas
+ 6
Lamron , the task description says, that the result has to be *rounded up to the nearest whole number*. so we can not use *round()*. > we should use *ceil(...)* instead. the function is part of the math module, so we need to import it.
27th Dec 2022, 7:31 PM
Lothar
Lothar - avatar
+ 6
Lamron , short sample which you can run to see the difference of *round()* and *ceil()* from math import ceil num = 12.37 print(f'input number: {num}') print(f'round(...): {round(num)}') print(f'ceil(...): {ceil(num)}')
28th Dec 2022, 11:56 AM
Lothar
Lothar - avatar
+ 4
round ***up***, not round
27th Dec 2022, 7:33 PM
Lisa
Lisa - avatar
+ 3
Check on the task description again, it asks us to "rounded ***up*** to the nearest whole number"
27th Dec 2022, 7:30 PM
Lisa
Lisa - avatar
+ 3
If you don't want to use the imported module you can also round up this way (that's what I did because I'm a newbie and I've not yet come across any lesson on importing anything): houses = int(input()) bills = (2 / houses) * 100 dec = bills - int(bills) if dec > 0: bills += 1 print(int(bills)) When you subtract " (int)Bills" from "bills" you're left with only the decimals, so now all you have to do is add "1" to the solution, if the decimals are more than zero. Hope that helps!
29th Dec 2022, 9:24 PM
Sarah
+ 2
Interesting. I thought round() will round it to the nearest whole number
27th Dec 2022, 7:32 PM
Lamron
Lamron - avatar
+ 1
Anyways, thanks for guidance!
27th Dec 2022, 7:38 PM
Lamron
Lamron - avatar