+ 1
How do I check to see if the number is whole?
siblings = int(input()) popsicles = int(input()) #your code goes here if popsicles / siblings == #wholenum: print('give away') else: print('eat them yourself') I think this is the correct approach. If not please let me know how to improve. Still learning. Always appreciated!
4 Réponses
+ 5
Checking whole number can be done by using (popsicles / siblings) % 1 == 0.
Although the better approach is to check if popsicles is divisible by siblings by using popsicles % siblings == 0.
+ 4
Thank you. That makes more sense to me.
+ 1
I did the same test and this was my code:
siblings = int(input())
popsicles = int(input())
#your code goes here
if (popsicles/siblings) %2 == 0:
print("give away")
elif (popsicles/siblings) == 0:
print("give away")
else:
print("eat them yourself")
All test cases clear except the last one, which I can't view! I put in the middle bit after the first time, but it didn't change anything.
0
Heather McLinton If popsicle is 0, there's nothing to give away..
Edited: I realized that, your code output "give away" two times, if the popsicle is 0.
And, if you want to check if the remainder of the popsicle divided by siblings is 0, you can use this instead:
if popsicles % siblings == 0:
#do sth