+ 2

Halloween Candy Challenge

Hi, I'm new to python and I wrote this before knowing about the function math.ceil(), but I keep getting 2/5 right. I can't tell why. if(200%houses)>houses/2: print(int(200/houses+1)) else: print(int(200/houses))

27th Dec 2019, 7:25 AM
Sunny Zhou
Sunny Zhou - avatar
6 Réponses
+ 3
you are using 200, and I don’t quite know why. houses = int(input()) dollars = 2 import math #your code goes here result = 100/(houses / dollars) print(math.ceil(result)) this was mine
27th Dec 2019, 8:24 AM
Brave Tea
Brave Tea - avatar
+ 3
oh but to answer your question, no I don’t know :) I like to think of those hidden tests I fail as a way of telling me: “hey, go look at your code again, and expecially look at the case/instructions again” that is where I mess up usually, not reading the instructions carefully enough 😂 just a friendly tip as well: in general, when you notice yourself writing things such as 200/houses several times, it is best to put them in a variable, or at least try and look to see if you can use a different way of writing it. same goes for the +1 and you can try and look at the simplest/smallest way of looking at stuff. (something I am learning at the moment) dividing 200/2 is the same as dividing 100/1 :)
28th Dec 2019, 12:12 PM
Brave Tea
Brave Tea - avatar
+ 1
well yeah. you need to use ceil because the challenge states that you need to round up to the nearest integer
28th Dec 2019, 11:47 AM
Brave Tea
Brave Tea - avatar
0
Hi @Brave Tea, I know I could have used the math.ceil() function, but by is my code wrong. I used 200 because 2 (dollars)* 100=200. It is exactly what you have too. Does anyone know what the 3-5 tests are?
28th Dec 2019, 12:48 AM
Sunny Zhou
Sunny Zhou - avatar
0
Hi Brave Tea and Sunny Zhou . I think Sunny Zhou’s attempt was to generate the ceil function itself, which means she was trying, using only ints and basic operations, to get to the solution. I am trying the same challenge in Java and have tried the same thing, and got the same tests wrong. Even so, there is so ething you arent considering in your code, Sunny, its that depending on the parity of houses, houses / 2 can either match the intended value (if houses is even ) or the integer part of the value (if houses is odd). Nevertheless, even applying that, I got the same tests wrong, so I really dont have much of a clue. this post was from 4 months ago. Have tou solved it in the meanwhile?
19th Apr 2020, 7:44 PM
#givesysiphusapaperpls
0
here is my code that works without import any module: houses = int(input()) result= (2/houses)*100 if result % 1 !=0: print(int(result)+1) else: print(int(result))
4th Apr 2022, 9:09 AM
David Lau
David Lau - avatar