Common mistakes we make in Python and why we should avoid that part 4

def divide(first, second): 
try:
result = first/second
print(result_var)
except:
print("Cannot divide using zero")
def divide(first, second): 
try:
result = first/second
print(result_var)
except ZeroDivisionError:
print("Cannot divide using zero")
Traceback (most recent call last):
File “wildcard_exception.py”, line 13, in <module> divide(1, 3) File “wildcard_exception.py”, line 7, in divide print(result_var) NameError: name ‘result_var’ is not defined

--

--

--

Coding, Reading,Python

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Afsalms

Afsalms

Coding, Reading,Python

More from Medium

Statement Control by Python

For loop in python

Coding With Python in 2022

If Statements in Python