0

While loop-if condition doesn’t work-any bug?

Hi all, I’m trying a little code to solve a simple maths problem. I have 10 dogs and cats in total, with 30 legs. I want to know how many dogs and how many cats there are. Here is the code, but my interpreter freezed when running this code. I don’t know if there’s something wrong with it: a=10 b=30 chic=0 while chic<a: if b%2==0: if (b/2)>a: dog=b/2-a chic=a-dog else: print("Impossible") chic=chic+1 print(chic, dog)

28th Aug 2019, 9:37 PM
Mai Dan Nguyen
Mai Dan Nguyen - avatar
2 Answers
+ 1
b/a is never changed so dog=b/2-a chic=a-dog gets executed every loop-iteration since you set chic inside the loop it doesn't matter if you add 1 to it chic will always be smaller than a and the while loop never stops
28th Aug 2019, 9:45 PM
Anton Böhler
Anton Böhler - avatar
+ 1
Thank you Anton Böhler :)
29th Aug 2019, 10:01 AM
Mai Dan Nguyen
Mai Dan Nguyen - avatar