Code Coach | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Code Coach

I used Python for this problem, but I got it correct in just Test Cases 1&4, and wrong in Test Cases 2, 3 & 5. My code: siblings=3 popsicles=15 if(popsicles/siblings)==0; print('give away') else: print('eat them yourself') Please, did I do something wrong?

11th Mar 2024, 4:46 PM
Sage Starr
Sage Starr - avatar
2 Answers
+ 5
The task wants you to determine if the number of popsicles is divisible by the number of siblings. In other words, the remainder after division is zero. You should use the modulo operator here.
11th Mar 2024, 4:52 PM
Tibor Santa
Tibor Santa - avatar
+ 5
Yes, the code is wrong. 1. Code Coach supplies different test values through console input. I see in this code that the values for siblings and popsicles are hard-coded as constants in the program. Both should be received as inputs from the console. 2. The conditional in the if statement needs to determine whether the popsicles can be evenly distributed amongst the siblings. The program checks whether the quotient is zero, and it fails to properly answer the question. Instead of checking the quotient, it should be checking the remainder. When the remainder is zero, the popsicles can be evenly distributed.
11th Mar 2024, 5:04 PM
Brian
Brian - avatar