Jun-18-2021, 09:27 PM
the problem I am having is that when user inputs / and second number as 0 it keeps going in loop i need to exit the loop but dont know where to put the exit loop condition also cannot use break to exit loop
#!/usr/bin/python3 def menu(): print ("Please select the tyoe of operation you want to perform") print ("+ for addition") print ("- for subtraction") print ("* for multiplication") print ("/ for division") def addition(x,y): sum=x+y return sum def subtraction(x,y): yum=x-y return yum def multiplication(x,y): multi=x*y return multi def division(x,y): div=x/y return div def iszero(num): while num == 0: return print("division by zero cannot be performed") num =float(input("please enter a number: ")) return print ("the results are :", division(num,num2)) menu() operat=input("Please enter operator (q to quit) :") while operat != "q": num=float(input("enter first number: ")) num2=float(input("enter second number: ")) if operat == '+': print (num, "+", num2, "=", addition(num,num2)) elif operat == '-': print ("result of calculation is :", subtraction(num,num2)) elif operat == '*': print ("the result of calculation is :", multiplcation(num,num2)) elif operat == '/': iszero(num2)