+ 4
How to solve popsicles for all tests
I can only get 3 of 5 tests. I need help.
31 Respostas
+ 11
If(popsicles%siblings==0):
print('give away')
else:
print('eat them yourself')
Use this condition
+ 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.
+ 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:
+ 2
And change those variables to user input
+ 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
+ 2
Nice. Learn something new everyday
+ 2
Martin, it is C
+ 1
Post your code here so that someone see it and fix it
+ 1
I have a code in c++ . U can refer it
https://www.sololearn.com/coach/3?ref=app
+ 1
siblings = 2
popsicles = 5
sharesleft = 1
if (popsicles%siblings==sharesleft):
print('eat them yourself')
else:
print('give away')
#still not there
+ 1
Ok thanks thats alot clearer also
+ 1
Thanks for the help i finally managed to complete 5/5. I know why it wasnt working now thnx all!
+ 1
If Popsicles%siblings:
Print('give away')
Else:
Print('eat it yourself')
+ 1
Why printf? And yea its easy until you know
+ 1
printf is used in C for printing something on screen as output
+ 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");
}
+ 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')
+ 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!
+ 1
if popsicles%siblings==0
print("give away")
else:
print("eat them yourself")