123456789101112131415161718192021222324252627282930313233343536373839 |
- def add(a, b):
- return a + b
- def subtract(a, b):
- return a - b
- def multiply(a, b):
- return a * b
- def divide(a, b):
- return a / b
- operations = {
- "+": add,
- "-": subtract,
- "*": multiply,
- "/": divide
- }
- def compute():
- n1 = float(input("What's the first number?: "))
- for sign in operations:
- print(sign)
- while True:
- operation_sign = input("Pick an operation sign from the line above: ")
- n2 = float(input("What's the next number?: "))
- result = operations[operation_sign](n1, n2)
- print(f"{n1} {operation_sign} {n2} = {result}")
- n1 = result
- if input(f"If you want another operation with {n1} type 'y', for start calculation from begining type 'c' and type 'n' for stop calc: ") == "c":
- break
- else:
- compute()
- print("Bye, bye!")
|