Python error ZeroDivisionError division by zero

0 votes

I'm getting the following error while executing a python code:

ZeroDivisionError: division by zero
In [55]:

x = 0
y = 0
z = x/y
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-55-30b5d8268cca> in <module>()
      1 x = 0
      2 y = 0
----> 3 z = x/y

ZeroDivisionError: division by zero
May 31, 2019 in Python by Yamini
8,491 views

1 answer to this question.

0 votes

Catch the error and handle it:

try:
    z = x / y
except ZeroDivisionError:
    z = 0


I am sure this helped to answer your query, cheers!

For more, join this course to Master Python programming.

Thanks!

answered May 31, 2019 by Rhea

Related Questions In Python

+1 vote
2 answers

Python error "ZeroDivisionError: float division by zero"

The error is thrown in this line matchPercentage ...READ MORE

answered May 21, 2020 in Python by Prabhakar
22,794 views
+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
5,368 views
0 votes
1 answer

Number division in python

For Python 3, use the // operator: q = ...READ MORE

answered Apr 18, 2018 in Python by Nietzsche's daemon
• 4,260 points
455 views
+1 vote
7 answers
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,060 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,479 views
0 votes
1 answer

When I create and remove files rapidly on windows using python I get WindowsError (Error 5)

Here's the short answer: disable any antivirus or ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
1,667 views
0 votes
11 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP