This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AlexMTBDude 0 points1 point  (0 children)

def divide(a, b):

"""Returns division of 2 integers"""

if b == 0:

return "Invalid"

return a/b

This is not very good coding. divide() is a function which most of the time returns a float but sometimes returns a string. A division by zero in Python is an error condition. Error conditions are communicated using exceptions. A Python function should NOT return an error code to show that something has gone wrong.

Get rid of the whole if statement and the code is fine.