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")
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")
+ 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")
+ 1
Wow yaâll are great with the responses. I appreciate it!
0
I added into it
If == 0 as well and still wont sign off the last âsituationâ
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")