calculator demo

Run Settings
LanguagePython
Language Version
Run Command
result = None ls = input(please input a number:") #ls = '1 + 1 + 1 + 1 + 'in terminal only happens in VS Code ls = ls.split() def check_float(data): try: float (data) return True except ValueError: print ('invalid input') return False while (len(ls) >=3): x = ls[0] op = ls [1] y = ls [2] if type(float(x)) == float and type (float(y)) == float: x = float(x) y = float (y) if op in ['+', '-', '*' ,'/']: if op == '+': result = x + y if op == '-': result = x - y if op == '*': result = x * y if op == '/': result = x / y else: print ('wrong operator') break else: print ('wrong operand') break del ls[:2] ls[0] = result if len(ls) == 2: print ('wrong operands') break if len(ls) == 1: break print(result)
Editor Settings
Theme
Key bindings
Full width
Lines