<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ZeroDivisionError: in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/zerodivisionerror/m-p/2255#M203</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a large dataset where I need to run a lot of calculations.&amp;nbsp; it contains roughly 100 fields.&amp;nbsp; I have created a script that runs an update cursor to calculate some new fields based on a few other fields.&amp;nbsp; Well I am running into the problem where if there is a zero in the field that is a divisor, I get this error:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Runtime error&amp;nbsp; Traceback (most recent call last): &amp;nbsp; File "&amp;lt;string&amp;gt;", line 36, in &amp;lt;module&amp;gt; ZeroDivisionError: float division by zero&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am looking for how to construct an if statement that will first determine if the calculation will create this error, then if it does, it will make the value 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;my first try of this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;if ((row[32]/row[3])/(row[30]/row[3]) =0): &amp;nbsp;&amp;nbsp; row[84]= (row[32]/row[3])/(row[30]/row[3]) else: &amp;nbsp; row[84]= 0&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;did not work.&amp;nbsp; Any help on how to make this if statement work would be much appreciated!!!&amp;nbsp; Thanks in advance!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Clinton&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Jan 2014 15:08:17 GMT</pubDate>
    <dc:creator>ClintonCooper1</dc:creator>
    <dc:date>2014-01-13T15:08:17Z</dc:date>
    <item>
      <title>ZeroDivisionError:</title>
      <link>https://community.esri.com/t5/python-questions/zerodivisionerror/m-p/2255#M203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a large dataset where I need to run a lot of calculations.&amp;nbsp; it contains roughly 100 fields.&amp;nbsp; I have created a script that runs an update cursor to calculate some new fields based on a few other fields.&amp;nbsp; Well I am running into the problem where if there is a zero in the field that is a divisor, I get this error:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Runtime error&amp;nbsp; Traceback (most recent call last): &amp;nbsp; File "&amp;lt;string&amp;gt;", line 36, in &amp;lt;module&amp;gt; ZeroDivisionError: float division by zero&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am looking for how to construct an if statement that will first determine if the calculation will create this error, then if it does, it will make the value 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;my first try of this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;if ((row[32]/row[3])/(row[30]/row[3]) =0): &amp;nbsp;&amp;nbsp; row[84]= (row[32]/row[3])/(row[30]/row[3]) else: &amp;nbsp; row[84]= 0&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;did not work.&amp;nbsp; Any help on how to make this if statement work would be much appreciated!!!&amp;nbsp; Thanks in advance!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Clinton&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jan 2014 15:08:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zerodivisionerror/m-p/2255#M203</guid>
      <dc:creator>ClintonCooper1</dc:creator>
      <dc:date>2014-01-13T15:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: ZeroDivisionError:</title>
      <link>https://community.esri.com/t5/python-questions/zerodivisionerror/m-p/2256#M204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can't test for something that will give you a division error. I imagine you tried this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;if ((row[32]/row[3])/(row[30]/row[3]) != 0):&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Will give you an error just for testing it if it includes zero division errors, so doesn't serve any purpose. All you need to check is if the denominator(s) are zero.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;if row[3] == 0: &amp;nbsp;&amp;nbsp;&amp;nbsp; row[84] = 0&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jan 2014 15:19:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zerodivisionerror/m-p/2256#M204</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-01-13T15:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: ZeroDivisionError:</title>
      <link>https://community.esri.com/t5/python-questions/zerodivisionerror/m-p/2257#M205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ahh yep!&amp;nbsp; Thank you!&amp;nbsp; It worked!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Clinton&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jan 2014 15:36:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zerodivisionerror/m-p/2257#M205</guid>
      <dc:creator>ClintonCooper1</dc:creator>
      <dc:date>2014-01-13T15:36:37Z</dc:date>
    </item>
  </channel>
</rss>

