""" Exercise 1. 4 - Calculator """ # Copyright (c) 2021. Pascal Syma. All rights reserved. def calculator(): """ Calculator """ choice = 0 first = 0 second = 0 while True: try: print(""" 1. Enter two integers 2. Add 3. Subtract 4. Multiply 5. Divide 0. Exit""") choice = int(input('Your choice: ')) if choice > 5 or choice < 0: raise ValueError except ValueError: print('Input must be either 0,1,2,3,4 or 5.') continue if choice == 0: print('Exiting ... Goodbye !') return if choice == 1: try: first = int(input('Input first number : ')) second = int(input('Input second number : ')) except ValueError: print('Input must be an integer!') continue elif choice == 2: # Addition print(f'The result is {first + second}') elif choice == 3: # Subtraction print(f'The result is {first - second}') elif choice == 4: # Multiplication print(f'The result is {first * second}') elif choice == 5: # Division print(f'The result is {first // second}') if __name__ == '__main__': calculator()