Need help with python code - please help me figure out what I'm doing wrong | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Need help with python code - please help me figure out what I'm doing wrong

You have a box of popsicles and you want to give them all away to a group of brothers and sisters. If you have enough left in the box to give them each an even amount you should go for it! If not, they will fight over them, and you should eat them yourself later. Task Given the number of siblings that you are giving popsicles to, determine if you can give them each an even amount or if you shouldn't mention the popsicles at all. Input Format Two integer values, the first one represents the number of siblings, and the second one represents the number of popsicles that you have left in the box. Output Format A string that says 'give away' if you are giving them away, or 'eat them yourself' if you will be eating them yourself. My code siblings = int(input()) popsicles = int(input()) if(popsicles // siblings): print("give away") elif(popsicles / siblings): print("eat them yourself")

30th Jun 2022, 2:33 PM
Irem Majid
Irem Majid - avatar
2 Answers
+ 6
I'll give hints to help you with this problem, you will learn more this way than just giving you the exact code answer. The conditions inside the if will always be True since any integer except 0 is True. For example, if popsicles is 10 and siblings is 5. 🔹 if (10 // 5) 🔹 if (2) TRY: Use modulus % operator to check if popsicles is divisible by siblings, which would also mean that you can give them each with even amount. Example: 🔹 10 % 2 == 0 You have 10 popsicles and 2 siblings, meaning you could give them away as they can share it with each other evenly. The 0 remainder means no extra popsicles that could cause your siblings to 'fight'.
30th Jun 2022, 2:45 PM
noteve
noteve - avatar
0
siblings = int(input()) popsicles = int(input()) #your code goes here popsicles = popsicles%siblings if popsicles>0: print("eat them yourself") else: print("give away")
30th Jun 2022, 2:39 PM
Mihir Lalwani
Mihir Lalwani - avatar