Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.1 kB
1
Indexable
Never
try:
    first = int(input("Enter the first number: "))
    second = int(input("Enter the second number: "))
except ValueError:
    print("Invalid input. Please enter valid integers.")
else:
    print("If you want to add, enter '1'", 
          "If you want to subtract, enter '2'", 
          "If you want to multiply, enter '3'", 
          "If you want to divide, enter '4'", 
          sep="\n")
    
    try:
        operat = int(input("Enter here: "))
        if operat == 1:
            print("Result:", first + second)
        elif operat == 2:
            print("Result:", first - second)
        elif operat == 3:
            print("Result:", first * second)
        elif operat == 4:
            try:
                print("Result:", first / second)
            except ZeroDivisionError:
                print("Error: Division by zero is not allowed.")
        else:
            print("Invalid operation. Please enter a number between 1 and 4.")
    except ValueError:
        print("Invalid input. Please enter a valid number for the operation.")
Leave a Comment