+ 1

Halloween Candy Puzzle Problem

Hi, I am working my way through the problems and solving them in python. I am confused about the Halloween Candy one as I am confident my code works and the test case scenarios say the expected output is the same as the output of my code, but it won't acknowledge that I've solved the problem. I can't tell if it's a bug with sololearn or if I'm not doing something right. However even if I am doing something wrong sololearn is not giving me any clues as to what I'm missing. My code to solve the problem is this: houses = int(input()) #your code goes here if houses < 3: print ("enter a number larger than 2") else: tb = 1 db= 2 candy = (houses - tb - db) chance = ((db/houses)*100) chance2 = round(chance) print (chance2)

16th Aug 2024, 8:31 AM
Half Dragoness
Half Dragoness - avatar
6 Réponses
+ 4
In that task description, it says: "A percentage value rounded up to the nearest whole number." So we strictly need to round ***up***. This is also called ceiling. You can use the ceil function from the math module, for instance: from math import ceil
16th Aug 2024, 8:45 AM
Lisa
Lisa - avatar
+ 2
write from math import ceil in the very first line of your code. then you can use the ceil() function. the code coach tasks are not tailored to current course lessons. they rather encourage one to reach beyond...
16th Aug 2024, 9:36 AM
Lisa
Lisa - avatar
+ 2
Unlike the code projects in the course, the code coach tasks are not associated with a particular course. The code coach has been here for longer than the current versions of courses, which is probably one of the reasons why they are not synchronized. The code coach is definitely challenging! Like in real-life coding, one often gets thrown in at the deep end and has to face issues one has never even thought of. Fortunately, we have Q&A/ Discuss for occasions like these! You solved the task with your current knowledge, showed your approach, and figured out that there is a knowledge gap – that's already the most important skill and you succeeded in it. Everything beyond is googling and asking others for advice. :)
16th Aug 2024, 2:05 PM
Lisa
Lisa - avatar
0
So far sololesrn hasnt introduced importing modules to me, is that something we can do?
16th Aug 2024, 9:32 AM
Half Dragoness
Half Dragoness - avatar
0
Just wanted to say thank you for taking the time to explain all this to me. I know I'm tripping up over newbie stuff. My only criticism of code coach is that for easy stuff I imagined it would get you to utilise what you've learned I the Python code program and that the harder difficulties would encourage looking outside sololearn for answers. For example I am reading these problems and trying to think of a way to solve the problem whilst also trying to remember everything that was covered in the program to find the best tool to solve the problem. Because I am not super familiar with all the tools and functions within python I don't have that information ready to go in my head so I expected the easy puzzles to only contain information I've already encountered. I would expect the medium and hard puzzles to ask for information outside of sololearn. It seems a lot to ask of a new learner, for the 'easy' puzzles at least.
16th Aug 2024, 1:48 PM
Half Dragoness
Half Dragoness - avatar
0
You cannot divide by zero. Instead. If houses <=3 print(“please choose a number greater than 3.”)
18th Aug 2024, 10:06 AM
O O