Quick actions

cmd+k|ctrl+k

Navigation

Languages

Lesson 9 - Simple Calculator

Snippet info

Language

Python

Visibility

public

Author

hardmandx

Created

2024-12-11T13:34:54.732972Z

Updated

2024-12-18T12:33:53.01737Z

x = input("Plese input expression:")
lst = x.split(' ')
print(lst)
op = lst[1]
x = int(lst[0])
y = int(lst[2])
while len(lst) >= 3:
        if op in ['+', '-', '*', '/']:
            if op == '+':
                result = x + y
            if op == '-':
                result = x - y
            if op == '*':
                result = x * y
            if op == '/':
                result = x / y
            print("The answer is: ", result)
            for i in range (2):
                del lst[0]
            print(lst)
            op = lst[1]
            y = int(lst[2])
            x = result
        else:
            print('ERROR')
INFO