0

Help!! Easy, Python, (popsicles)

"""" Ive attached the “problem” and my attemt at coding it. Thanks in advance (: This code works for all situations besides the last one and it is “locked” for me """ siblings = int(input()) popsicles = int(input()) #your code goes here z = popsicles/siblings if z % 2 == 0: print("give away") if not z % 2 == 0: print("eat them yourself")

20th Dec 2022, 2:43 AM
Josh M
Josh M - avatar
5 odpowiedzi
+ 3
Josh M , your last code is working properly now - that is great! please allow me to give a comment about the structure of the if... conditionals anyway. instead of using 3 individual if clauses, we can use an if... else... construct. since there are only 2 different conditions to check (? modulo == 0 and ? modulo != 0), we can omit all the rest. (these lines are marked as comments, and can be removed) siblings = int(input()) popsicles = int(input()) if popsicles/siblings % 1 == 0: print("give away") #if not popsicles/siblings % 1 == 0: else: print("eat them yourself") #if popsicles/siblings == 0: #print("give away")
20th Dec 2022, 4:00 PM
Lothar
Lothar - avatar
+ 1
Ahh got it! Thanks everyone though! siblings = int(input()) popsicles = int(input()) if popsicles/siblings % 1 == 0: print("give away") if not popsicles/siblings % 1 == 0: print("eat them yourself") if popsicles/siblings == 0: print("give away")
20th Dec 2022, 3:17 AM
Josh M
Josh M - avatar
+ 1
Wow ya’ll are great with the responses. I appreciate it!
20th Dec 2022, 6:04 PM
Josh M
Josh M - avatar
0
I added into it If == 0 as well and still wont sign off the last “situation”
20th Dec 2022, 3:02 AM
Josh M
Josh M - avatar
0
Try this..... siblings = int(input()) popsicles = int(input()) #your code goes here if popsicles % siblings == 0: print("give away") else : print("eat them yourself")
21st Dec 2022, 9:40 AM
BORN-LOSER
BORN-LOSER - avatar