Error message

+2 Chris Knowles · November 27, 2015
Hi Guys, just very slowly working through the 'Tanks' programming videos and have reached a point where Python keeps throwing up the same error message.

 startingShell[1] += int((((startingShell[0]-xy[0])*0.015/(currentPower/50))**2) - (turPos+turPos/(12-turPos)))

the above is line 356 in the source code.

The error that keeps coming up is this..
   startingShell[1] += int((((startingShell[0]-xy[0])*0.015/(currentPower/50))**2) - (turPos+turPos/(12-turPos)))

ZeroDivisionError: float division by zero,

Now this happens if I manually type in the code myself or copy and paste from the code fro the code 'bucky' has provided on the forum. This line of code appears around video 67 and from then on 'Tanks' just crashes. Being new to programming and pygame/python it's got me kind of frustrated as all was going ok'ish to that point.



Post a Reply


Oldest  Newest  Rating
0 Chris Knowles · November 27, 2015
Hi Dan, thanks for the quick answer, just an update. I'm using 'Python 2.7', which doesn't divide 'Floats' as well as 'Python 3'.
In this case in this case adding from __future__ import division sorted the problem out. Thanks again for your answer.

+1 Dan P · November 27, 2015
The error that you are seeing means that something is trying to divide by zero.

In this case you have



So if currentPower was 0, 0/50 = 0 and therefore you will get a divide by zero error.



If turPos was equal to 12, then 12 - turPos would also be zero.

The reason why you don't want to divide by zero is because it causes a short circuit essentially that will power up the chip.

Here is a youtube video to illustrate.
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator