+ 1
Codecoach - Halloween candy please help
I am learning python and using code coach - one specific problem I couldnt get right its called halloween candy. I dont know how to attach it to this post. But the code I wrote to solve it is: print (round (2/houses) + int (2/houses * 100)) I get the first two scenarios correct but the hidden test scenarios are wrong. I dont know what is the problem. And is there a way to see the hidden test scenarios in code coach? I am mostly using the sololearn phone app to code and study.
7 Respuestas
+ 2
I see that you made a hopeful attempt to always round up, but it doesn't work. Solution: There is a function in the math library that always rounds up. Import the math library and use math.ceil().
+ 1
It sounds like you are endeavoring to understand how to write your own ceil function. Here is how I would write it:
def ceil(a):
return int(a)+(a>int(a))
+ 1
import math
dollar = math.ceil(2/(int(input()))*100)
print(dollar)
0
I should still be able to solve it without importing math.ceil
I believe one of the scenarios is wrong. Here is my logic.
I get 4 out of 5 scenarios correct if I code (rounding down all decimals):
Print (int (round(2/houses) *100))
And I get one out of scenario correct if I round up all the decimals using the following code:
Print (int (round(2/houses) * 100 +1))
So the code should be able to round up or down . As the following:
houses = int(input())
x = round (2/houses)
if int (x) == 0:
print (int (2/houses * 100))
elif int(x) > 0:
print (int (2/houses *100) + 1)
Yet still it only solves 4 scenarios out of 5.
If you could share the code to solve, and if possible without the math.ceil
0
I solved it using math.ceil, with the following code:
houses = int(input())
x = (2/houses)
import math
print (math.ceil(x * 100))
Still th previous solution should have worked.
Please be patiant with me, I am trying to understand the logic behind the codes.
0
Thank you very much gentlemen