Mar-21-2021, 04:17 PM
(This post was last modified: Mar-21-2021, 04:29 PM by snippsat.
Edit Reason: Added code tag
)
Hi everyone,
Nice to meet you all! I'm building a calculator with python and I want to add try except else and finally. I have added the try except and the calculator is working but it doesn't return the error message if user input is not an integer.
Can you please take a look?
Nice to meet you all! I'm building a calculator with python and I want to add try except else and finally. I have added the try except and the calculator is working but it doesn't return the error message if user input is not an integer.
Can you please take a look?
#User inputs math type operation = input(''' Please type in the math operation you would like to complete: + for addition * for multiplication ''') #User inputs number number_1 = int(input('Enter your first number: ')) number_2 = int(input('Enter your second number: ')) #If user chooses addition try: if operation == '+': print('{} + {} = '.format(number_1, number_2)) print(number_1 + number_2) except Exception: print: ("You have not input a number") #if user chooses multiplication try: if operation == '*': print('{} * {} = '.format(number_1, number_2)) print(number_1 * number_2) except: print: ("You have not input a number")