Help!! Easy, Python, (popsicles) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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
8 Answers
+ 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
+ 3
x = int(input()) y = int(input()) if y % x == 0: print("give away") else: print("eat them yourself")
20th Dec 2022, 4:08 PM
Knight
Knight - 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
please paste the code correctly so we can review and edit it https://code.sololearn.com/c6Pp00Zaj74j/?ref=app
20th Dec 2022, 7:29 AM
Knight
Knight - 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
0
For me this was 100% correct: siblings = int(input()) popsicles = int(input()) x = popsicles / siblings If x == round(x): print("give away") else: print("eat them yourself") I think is simple and efective.
14th Jan 2023, 4:56 PM
Julian Perez Moreno
Julian Perez Moreno - avatar