I am making a simple program for just testing my knowledge and. So this is what I have made right now. I have some code which is used for basic operations of math plus minus divide and multiply the code works fine until someone divides with 0 for which i have an if statement which prints my desired output but with a none. I saw that doing !=-1 makes it go away but it works for strings when i tried before.
Tried to implement !=-1 didn't work looking to remove None as output
a = input("What would you like to do? ")
num1 = input("Input value one ")
num2 = input("Input value two ")
def add(x,y):
return(int(x) int(y))
def minus(x,y):
return(int(x)-int(y))
def multiply(x,y):
return(int(x)*int(y))
def divide(x,y):
if (int(num1)>=0 or int(num2)!=-1)>=0:
print("Number can not be equal zero") else:
return(int(x)//int(y))
if a == "Addition":
print(add(num1,num2))
elif a == "Minus":
print(minus(num1,num2))
elif a == "Multiply":
print(multiply(num1,num2))
elif a == "Division":
print(divide(num1,num2))
CodePudding user response:
def divide(x,y):
if (int(num1)>=0 or int(num2)!=-1)>=0:
print("Number can not be equal zero") else:
return(int(x)//int(y))
use raise exption may be what you want.
def divide(x,y):
if int(num1)>=0 or int(num2)!=-1:
raise ValueError("Number can not be equal zero")
else:
return(int(x)//int(y))
CodePudding user response:
a = input("What would you like to do? ")
num1 = input("Input value one ")
num2 = input("Input value two ")
def add(x,y):
return(int(x) int(y))
def minus(x,y):
return(int(x)-int(y))
def multiply(x,y):
return(int(x)*int(y))
def divide(x,y):
if int(y) == 0:
pass
else:
return(int(x)//int(y))
if a == "Addition":
print(add(num1,num2))
elif a == "Minus":
print(minus(num1,num2))
elif a == "Multiply":
print(multiply(num1,num2))
elif a == "Division":
print(divide(num1,num2))