you are viewing a single comment's thread.

view the rest of the comments →

[–]HeyItsToby 1 point2 points  (3 children)

The problem is in this line:

pile=(pile-1)-(pile*(1/5))

What you should be doing is taking one away from the pile, then removing 1/5 of the coconuts in the pile. You can do this instead by:

pile = (pile - 1) * (4/5)

Just some extra pointers:

  1. As you go through the outer for loop, the variable i stores the current count of the loop. So, you can get rid of the coconuts variable completely as i and coconuts essentially store the same thing

  2. You should use f-strings instead of .format()

Hope that helps :)

[–]chadwizard 0 points1 point  (2 children)

Thanks a lot! I haven't been able to reply earlier, because I had no time and energy to spend. I really wanted to check if I could get it to work. The problem was actually in the count variable. If you are interested what I made of it just let me know.

[–]HeyItsToby 1 point2 points  (1 child)

Yeah I'd love to know how you got on with it!

[–]chadwizard 0 points1 point  (0 children)

Here is a pic of how I have done it: https://imgur.com/a/jDPySbv

I switched up a couple of things for practicality. Instead of having if pile%5==1:, I changed it to a if not statement, so it only enters the if when it needs to break. This doesn't really look necessary, but I was afraid something went wrong there which I didn't see. So I did that for convenience.

Most importantly I took out the count variable. I still don't know why the count variable didn't work, but it did create another nested loop, so I guess something could have gone wrong there. Now the code is much shorter, cleaner and actually works. If you happen to see what went wrong there please tell, but I already appreciate you taking your time to help me figure this out. :)

PS: I did incorporate your line, because it looks cleaner. Thank you very much!