diff options
| author | Max <mahn.maxwell@gmail.com> | 2022-01-06 12:55:30 -0500 |
|---|---|---|
| committer | Max <mahn.maxwell@gmail.com> | 2022-01-06 12:55:30 -0500 |
| commit | d05616bb4f7e6983ef02317da5ccfcdd04d5a23e (patch) | |
| tree | 66d27d4760e04280d1f5415df3aabe2a3d021765 /main.py | |
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -0,0 +1,47 @@ +ops = "+-*/^" + +def calc(a, b, op): + if op == '+': + return a + b + elif op == '-': + return a - b + elif op == '*': + return a * b + elif op == '/': + return a / b + elif op == '^': + return a ** b + +help_menu = "'exit' - quit\n'help' - print this menu\nInput two numbers and an operator separated by spaces.\nExample input: A + B\nAvailable operators: + - * / ^" +print(help_menu) + +while True: + instr = input("> ") + if instr == "exit": + break + elif instr == "help": + print(help_menu) + continue + args = instr.split() + + if len(args) < 3: + print("Not enough arguments to perform operation.") + continue + + try: + args[0] = float(args[0]) + except: + print("Invalid first argument.") + continue + + try: + args[2] = float(args[2]) + except: + print("Invalid second argument.") + continue + + if args[1] in ops: + print(calc(args[0], args[2], args[1])) + else: + print("Invalid operation.") + |
