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
- }
- is_on = True
- def calculator():
- num1 = float(input("First Number: "))
- for key in operations:
- print(key)
- while is_on == True:
- symbol = input("Pick an operation: ")
- num2 = float(input("Next Number: "))
- calculate = operations[symbol]
- answer = calculate(num1, num2)
- print(f"{num1} {symbol} {num2} = {answer}")
- if input(f"Type 'y' to continue calculating with {answer} or 'n' to start a new calculation") == "y":
- num1 = answer
- else:
- calculator()
- calculator()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement