+ 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!

1st Jun 2023, 6:29 PM
Kelley Pfeiffer
Kelley Pfeiffer - avatar
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.
1st Jun 2023, 6:38 PM
Willyanto
Willyanto - avatar
+ 4
Thank you. That makes more sense to me.
1st Jun 2023, 6:40 PM
Kelley Pfeiffer
Kelley Pfeiffer - avatar
+ 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.
2nd Jun 2023, 2:23 PM
Heather McLinton
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
3rd Jun 2023, 8:14 AM
Dragon RB
Dragon RB - avatar