Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add(n1, n2):
- """Add n1 and n2 then returns the result"""
- return n1 + n2
- def subtract(n1, n2):
- """Subtracts n1 and n2 then returns the result"""
- return n1 - n2
- def multiply(n1, n2):
- """Multiplies n1 by n2 and returns the result"""
- return n1 * n2
- def divide(n1, n2):
- """Divides n1 by n2 and returns the result"""
- return n1 / n2
- operations = {
- "+": add,
- "-": subtract,
- "*": multiply,
- "/": divide
- }
- num1 = int(input("First Number: "))
- for key in operations:
- print(key)
- symbol = input("Pick an operation from the above list: ")
- num2 = int(input("Second Number: "))
- calculate = operations[symbol]
- answer = calculate(num1, num2)
- print(f"{num1} {symbol} {num2} = {answer}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement