Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n1 = int(input("enter number: "))
- n2 = int(input("enter number: "))
- user_input = input("what would you like to do, 1) add, 2) minus, 3) multiply, 4) divide, 5) all: ")
- def my_function_add(a, b):
- print(a + b)
- def my_function_minus(a, b):
- print(a - b)
- def my_function_multiply(a, b):
- print(a * b)
- def my_function_divide(a, b):
- print(a / b)
- def my_function_all(a, b):
- my_function_add(a, b)
- my_function_minus(a, b)
- my_function_multiply(a, b)
- my_function_divide(a, b)
- my_dict = {'add': my_function_add,
- 'minus' : my_function_minus,
- 'multiply' : my_function_multiply,
- 'divide' : my_function_divide,
- 'all': my_function_all,
- }
- def my_selection(name):
- my_dict.get(name)(n1, n2)
- if user_input == '1' or user_input == 'add':
- my_selection('add')
- elif user_input == '2' or user_input == 'minus':
- my_selection('minus')
- elif user_input == '3' or user_input == 'multiply':
- my_selection('multiply')
- elif user_input == '4' or user_input == 'divide':
- my_selection('divide')
- elif user_input == '5' or user_input == 'all':
- my_selection('all')
- else:
- print("I do not understand, pick a number or write the calculation you want")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement