samedi 15 septembre 2018

How to print something when the user divides by 0

I was working on a calculator the other day and when testing it, I remembered that i can't divide by zero and therefore get an error. Is there anyway that i can have some text show when the user tries dividing 0 by 0? This is my code:

def SMD():#Simple Maths Divide
print("Division eh? Fair enough")
divideno1 = float(input("What's the first number?"))#Divide number 1
divideno2 = float(input("What's the second number?"))#Divide number 2
dividenof = divideno1/divideno2#Divide number final
print("Your answer is", dividenof)

I was thinking of using an "if" statement bu i don't know how i would do that as it doesn't equal to anything (error).

Aucun commentaire:

Enregistrer un commentaire