how to get "ivalid input" in my output i already have a code for this. def menu():
hi can u help me here i dont know how to get "ivalid input" in my output i already have a code for this.
def menu():
flag = True
while (flag):
print("1. Addition")
print("2. Subraction")
print("3. Multiplication")
print("4. Division")
try:
choice = int(input("Choose an operation: "))
# ask user two numbers to perform the selected operation
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
if choice == 1:
result = a + b
elif choice == 2:
result = a - b
elif choice == 3:
result = a * b
elif choice == 4:
result = a / b
else:
print("Invalid Choice")
except ZeroDivisionError:
print("Cannot divide by zero")
result = 0
except ValueError:
print("Please enter a numeric value")
print("Result: ", result)
i = int(input("Type 0 to continue else 1 to exit: "))
if i == 0:
flag = True
else:
flag = False
menu()
all i need is output that show "invalid input"
Step by step
Solved in 4 steps with 2 images