Can anyone help me out here? (Code coach) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anyone help me out here? (Code coach)

For the halloween candy code coach. I made some code in Python that solves 1st, 2nd, and 5th test case. However, it fails the 3rd and 4th. I have no idea why and those cases are locked. Can anyone help me to understand how and why it would fail? Thanks. https://sololearn.com/compiler-playground/cA4dFh01K8qQ/?ref=app

6th Feb 2024, 2:52 PM
Keyon
Keyon - avatar
9 Answers
+ 6
Keyon In this task, the result must always be rounded up. Your conditional expressions make absolutely no sense. The first condition is not necessary since the input already implies a number >=3. These two lines of your code: candy = (houses - 3) bag = (candy + toothbrush + dollar) correspond to: bag = houses The second condition is meaningless because the percentage probability has no direct connection with an even number of houses. For example, 16 houses will have a 13% probability of receiving dollars. 2/16*100 => 1/8*100 => 0.125*100 => 12.5% => 13%
6th Feb 2024, 4:04 PM
Solo
Solo - avatar
+ 4
Keyon the smaller the code, the fewer bugs. My decision took only one line...😎
6th Feb 2024, 4:46 PM
Solo
Solo - avatar
+ 4
I prefer to keep my decisions a secret, at least until a certain point. The fact is that this prevents the student from going beyond the stereotype of thinking, and it does not matter his own or someone else's. You did well, because you almost solved this problem in your own way, coming from the knowledge and the stereotype of thinking that you currently possess. Return to this task after completing the course and you will most likely solve it in a different way. In the meantime, as a reward, I have written this code for you...😎 https://sololearn.com/compiler-playground/cig0zTcT43cK/?ref=app
6th Feb 2024, 5:37 PM
Solo
Solo - avatar
+ 2
Thank you. I overthought the entire thing and had so much useless lines of code... All I had to do was delete most of it and it worked.
6th Feb 2024, 4:33 PM
Keyon
Keyon - avatar
+ 1
Solo 🫡 thanks again
6th Feb 2024, 6:12 PM
Keyon
Keyon - avatar
+ 1
Keyon looking at your code, I was in a hurry and made a mistake...🤦‍♂ Take a look at the now-corrected code...😎
6th Feb 2024, 7:43 PM
Solo
Solo - avatar
+ 1
For reference. Sololearn Community Code Coach Halloween Candy (Easy) https://www.sololearn.com/coach/4?ref=app I solved it in two lines, the first being: from math import ceil
6th Feb 2024, 9:02 PM
Rain
Rain - avatar
0
Solo I'm sure, mind sharing it? I'm trying to learn from people better than me like yourself.
6th Feb 2024, 5:14 PM
Keyon
Keyon - avatar
0
Салам
8th Feb 2024, 10:33 AM
Мухаммад Абдурахмонов