Skip to content
Advertisement

strictly no other user input rather than this 4 predefined options with Python [closed]

”’def addition(num1, num2): return num1 + num2

def subtraction(num1, num2): return num1 – num2

def multiplication(num1, num2): return num1 * num2

def division(num1, num2):
return num1 / num2

selection = int(input(“Select operations form 1, 2, 3, 4 :” ‘n’ “1.Addition, 2.Subtraction, 3.Multiplication, 4.Division n “)) num1 = int(input(“Enter first number: “)) num2 = int(input(“Enter second number: “))

if select == 1: print(addition(num1, num2))

elif select == 2: print(subtraction(num1, num2))

elif select == 3: print(multiplication(num1, num2))

elif select == 4: print(division(num1, num2))

else:

print("Invalid input")

”’

Advertisement

Answer

you can do it with while loop read here How can I limit the user input to only integers in Python

Advertisement