Practice Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Practice Problem

How am I supposed to fix my code when I can only see the test cases in which my code works as intended? The ones in which my code doesn't work are "hidden". Am I just supposed to take wild guesses? Is this a ploy to get me to buy premium? Or am I overlooking something obvious?

3rd Feb 2022, 2:27 PM
Nicolas Kloos
13 Answers
+ 2
Hello Nicolas Kloos You need to find a general solution for each challenge. The best way is to copy your code into the playground and test different inputs. If you still have problems you can share your code here.
3rd Feb 2022, 2:49 PM
Denise Roßberg
Denise Roßberg - avatar
+ 5
Nicolas Kloos You need to round up to the nearest whole number. So you need to use ceil() instead of round()
3rd Feb 2022, 8:15 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Denise Roßberg Yeah I get it now. I misunderstood the task on top of the use of the functions. I originally thought the percentage was ment to be rounded up and down. That was what Paul was trying to tell me aswell. (I just didn't get then) Thank you all for your helpfull answers! What a fun community :)
3rd Feb 2022, 8:35 PM
Nicolas Kloos
+ 1
Hi Nicolas Kloos, The test cases will be hidden for all, regard less you are a pro or a moderator (i suppose) or a normal member. Now you will be thinking that... Why they are hidden?!? There's a very innocent answer: So that you won't use if/else to solve the problem in a matter of minutes🙂. I hope you understood me🙄
3rd Feb 2022, 2:37 PM
NEZ
NEZ - avatar
+ 1
Thats a good idea. It takes the guesswork out of it. Thank you
3rd Feb 2022, 2:52 PM
Nicolas Kloos
+ 1
Does your solution round up to the nearest integer?
3rd Feb 2022, 8:02 PM
Paul
Paul - avatar
+ 1
Denise Roßberg It worked btw. thank you for that. So I needed to import the math directory and then use the math.ceil() function. I guess its time to start the intermediate python course. Thats probably something I'd have known if I knew more about the language
3rd Feb 2022, 8:27 PM
Nicolas Kloos
0
That makes sense. But I guess it does make finding the correct solution more difficult as well... I'll have to use my brain after all.
3rd Feb 2022, 2:49 PM
Nicolas Kloos
0
Well I still don't get where the problem lies. I'm trying to solve the Halloween Candy Challenge and this is my code: houses = int(input()) def chance(x): y = 2 #Houses that give money percent = round((y/x)*100) return(percent) if houses >= 3: print(chance(houses)) It seems to give me the right answer and I can't seem to find the problem in the playground. I don't understand where my problem lies.
3rd Feb 2022, 7:33 PM
Nicolas Kloos
0
Yes. And for the first two Testcases everything is fine. But afterwards the tests fail. Since I can't see the in or outputs though, I'm having trouble finding the problem. I did some test with different inputs in the playground and it seemed to work as intended
3rd Feb 2022, 8:08 PM
Nicolas Kloos
0
How does round() behave differently? I've only started learning python this week so I don't know a lot about the different funktions yet
3rd Feb 2022, 8:18 PM
Nicolas Kloos
0
Nicolas Kloos btw you need to import math to use ceil import math print(math.ceil(4.3)) output: 5 round() -> rounds up when decimal place >= 5 ("kaufmännisches Runden") 1.4 = 1 1.5 = 2 ceil() rounds always up 1.1 = 2 1.4 = 2
3rd Feb 2022, 8:28 PM
Denise Roßberg
Denise Roßberg - avatar
0
Wow
5th Feb 2022, 9:55 AM
Taha Buğra Özdemir