+ 4

How to solve popsicles for all tests

I can only get 3 of 5 tests. I need help.

19th Apr 2020, 5:45 PM
Martin
Martin - avatar
31 Respostas
+ 11
If(popsicles%siblings==0): print('give away') else: print('eat them yourself') Use this condition
20th Apr 2020, 2:47 AM
Ramu Kaka
+ 4
Martin how do u know that there are 2 siblings and 5 popsicles. You don't know that, it would be entered by a user, not u. There are 5 test cases, in each of them value of siblings and popsicles would be different, so change those values to int(input()) siblings = int(input()) popsicles = int(input()) And yeah, you dont know shares left too. As Justus said, use popsicles % siblings If it is not equal to 0 that means popsicles couldnt be divided among the siblings. % gives remainder ok? 9 % 3 = 0. 9 % 6 = 3.
19th Apr 2020, 8:03 PM
maf
maf - avatar
+ 2
Martin the only condition your code is checking is if sharesleft == 0. This is always true, so it always prints 'give away' Use this if popsicles %siblings== sharesleft:
19th Apr 2020, 6:46 PM
Justus
Justus - avatar
+ 2
And change those variables to user input
19th Apr 2020, 6:46 PM
Justus
Justus - avatar
+ 2
You may use my code as an example. If you have any questions, you can ask me. https://code.sololearn.com/c8d5XsDgsTxw/?ref=app
20th Apr 2020, 4:03 AM
Nikolai Girich
Nikolai Girich - avatar
+ 2
Nice. Learn something new everyday
21st Apr 2020, 11:31 AM
Martin
Martin - avatar
+ 2
Martin, it is C
21st Apr 2020, 2:40 PM
Introvert
Introvert - avatar
+ 1
Post your code here so that someone see it and fix it
19th Apr 2020, 5:48 PM
Muhammad Bilal
Muhammad Bilal - avatar
+ 1
I have a code in c++ . U can refer it https://www.sololearn.com/coach/3?ref=app
19th Apr 2020, 7:06 PM
Ramu Kaka
+ 1
siblings = 2 popsicles = 5 sharesleft = 1 if (popsicles%siblings==sharesleft): print('eat them yourself') else: print('give away') #still not there
19th Apr 2020, 7:20 PM
Martin
Martin - avatar
+ 1
Ok thanks thats alot clearer also
19th Apr 2020, 8:08 PM
Martin
Martin - avatar
+ 1
Thanks for the help i finally managed to complete 5/5. I know why it wasnt working now thnx all!
20th Apr 2020, 8:58 AM
Martin
Martin - avatar
+ 1
If Popsicles%siblings: Print('give away') Else: Print('eat it yourself')
20th Apr 2020, 3:30 PM
anand Pandit
anand Pandit - avatar
+ 1
Why printf? And yea its easy until you know
21st Apr 2020, 9:34 AM
Martin
Martin - avatar
+ 1
Martin its not python. Probably C.
21st Apr 2020, 10:08 AM
maf
maf - avatar
+ 1
printf is used in C for printing something on screen as output
21st Apr 2020, 2:42 PM
Introvert
Introvert - avatar
+ 1
Martin I passed the test with this.. It's written in c# int siblings, popsicles; siblings = Convert.ToInt32(Console.ReadLine()); popsicles = Convert.ToInt32(Console.ReadLine()); if(popsicles%siblings != 0) { Console.WriteLine("eat them yourself"); } else { Console.WriteLine("give away"); }
21st Apr 2020, 5:34 PM
Silva Olushola Fredrick
Silva Olushola Fredrick - avatar
+ 1
I don't understand why the code below passes all the test. 2 siblings and 6 popsicles would result on 3 popsicles per kid. An odd number. I understood that every kid should receive an even number of popsicles. Yet the code below passes all tests. Go figure. if not popsicles % siblings: print('give away') else: print('eat them yourself')
11th Dec 2020, 2:50 PM
Robson Marini
Robson Marini - avatar
+ 1
I think I get it now. Every kid should receive the same amount of popsicles. It doesn't have to be an even number. I thought it should. That was my problem. Gotta learn english instead of programming haha. Sad day!
11th Dec 2020, 2:54 PM
Robson Marini
Robson Marini - avatar
+ 1
if popsicles%siblings==0 print("give away") else: print("eat them yourself")
18th Sep 2024, 9:51 PM
ReaperMC1092
ReaperMC1092 - avatar