0

Is there a way to block characters (letters) in this code:

x = '6'
while x != '5':

    try:
        a = int(input('please enter what the first digit should be = '))
        b = int(input('please enter what the second digit should be = '))
        op = input('press 1 to add, 2 to subtract, 3 to multiply or 4 to divide:')
        if op == '1':
            c = a + b
        elif op == '2':
            c = a - b
        elif op == '3':
            c = a * b
        elif op == '4':
            if b == 0:
                c = 'cannot divide by 0'
            else:
                c = a / b
        else:
            c = 'a error'

        print('Your answer is = ',c)

    except ValueError:
        print('Something went wrong! Please ensure you only entered numbers!!')


    x = input('Press 5 to exit or 6 to continue: ')
    if x != '5':
        print('We continue :) ')
    else:
        print("Sad to see you go. Bye!")

I'm making a calculator app and I want to stop the crash by blocking all letters.

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Please include the complete error message in your question. – DYZ Nov 24 '19 at 04:32
  • 1
    Possible duplicate of [Python how to only accept numbers as a input](https://stackoverflow.com/questions/27516093/python-how-to-only-accept-numbers-as-a-input) – Kirk Nov 24 '19 at 04:36
  • What do you mean by block? Do you want the loop running even after an character(letter) is typed? Or do you want to stop the execution and raise an exception ? – squareRoot17 Nov 24 '19 at 04:57

0 Answers0