[SOLVED] Need help with the popsicles challenge | Sololearn: Learn to code for FREE!

0

[SOLVED] Need help with the popsicles challenge

This is my code, can’t spot whats wrong, it fails test condition 5 but I cant see what that condition is: siblings = int(input()) popsicles = int(input()) a = popsicles / siblings if (a % 2) == 0: print('give away') elif (siblings > popsicles): print('eat them yourself') else: print('eat them yourself')

6/26/2022 11:55:06 AM

Datboi

7 Answers

New Answer

+6

Your if statement checks if your division is an even number. Wouldn't it be better to check if there's a remainder from the amount of popsicles?

+5

Datboi , don't get confused. you are not far away from solving the task: siblings = int(input()) # enter e.g. 5 popsicles = int(input()) # enter e.g. 15 #a = popsicles / siblings # <<< this is not required if (popsicles % siblings) == 0: # <<< this is the correct use of the modulo division. 15 % 5 => remainder is 0, so we can give away print('give away') elif (siblings > popsicles): print('eat them yourself') else: print('eat them yourself')

+4

% operator gives you reminder. .. What is need for a%2 ? popsiples/siblings why this? According to you..!

+3

Lothar, and everyone else, thanks for the help, I solved it with siblings = int(input()) popsicles = int(input()) if (popsicles % siblings) > 0: print('eat them yourself') elif (popsicles % siblings) == 0: print('give away') elif (siblings > popsicles): print('eat them yourself') else: print('eat them yourself')

+2

Currently, you are dividing the number of popsicles among children instead of checking if there will be any leftover. Hint: Change the division operator (/). You also need to modify the 'if statement' to follow your result stored in 'a' :)

+1

Datboi Great Job :) You can also make this program smaller by just using 'if and else' and removing the 'elif' statements. To make it smaller: > Remove the first 'if' > change the first 'elif' to 'if' > Remove the second 'elif' Final will look like this: if (popsicles % siblings) == 0: # if can be split perfectly, then give away print('give away') else: # if not, eat yourself print('eat them yourself')

0

Ausgrindtube How would I check for a remainder? Would it be if (a // 2) > 0: ?