Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. n1 = int(input("enter number: "))
  2. n2 = int(input("enter number: "))
  3.  
  4. user_input = input("what would you like to do, 1) add, 2) minus, 3) multiply, 4) divide, 5) all: ")
  5.  
  6. def my_function_add(a, b):
  7.    print(a + b)
  8.  
  9. def my_function_minus(a, b):
  10.     print(a - b)
  11.  
  12. def my_function_multiply(a, b):
  13.     print(a * b)
  14.  
  15. def my_function_divide(a, b):
  16.     print(a / b)
  17.  
  18. def my_function_all(a, b):
  19.     my_function_add(a, b)
  20.     my_function_minus(a, b)
  21.     my_function_multiply(a, b)
  22.     my_function_divide(a, b)
  23.  
  24. my_dict = {'add': my_function_add,
  25.            'minus' : my_function_minus,
  26.            'multiply' : my_function_multiply,
  27.            'divide' : my_function_divide,
  28.            'all': my_function_all,
  29.           }
  30.  
  31. def my_selection(name):
  32.     my_dict.get(name)(n1, n2)
  33.  
  34. if user_input == '1' or user_input == 'add':
  35.     my_selection('add')
  36.  
  37. elif user_input == '2' or user_input == 'minus':
  38.     my_selection('minus')
  39.  
  40. elif user_input == '3' or user_input == 'multiply':
  41.     my_selection('multiply')
  42.  
  43. elif user_input == '4' or user_input == 'divide':
  44.     my_selection('divide')
  45.  
  46. elif user_input == '5' or user_input == 'all':
  47.     my_selection('all')
  48.  
  49. else:
  50.     print("I do not understand, pick a number or write the calculation you want")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement