Quick actions

cmd+k|ctrl+k

Navigation

Languages

Calculator V1

Snippet info

Language

Python

Visibility

public

Author

skyhui0001

Created

2025-03-26T11:07:27.230475Z

Updated

2025-03-26T13:50:01.045024Z

try:
    x=1
    y=1
    x/y
except ZeroDivisionError:
    print("y is zero")
finally:
    print("this line will run, not matter what")



Is = ['1','+',1]
Is = '1 + 1'
Is=Is.split()
x= Is[0]
op= Is[1]
y= Is[2]
result = None

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")
else:
    print("wrong operand")
print (result)





Is = '1 + 1 + 1 + 1'
Is=Is.split()
result = None
while (len(Is)>=3):
    x= Is[0]
    op= Is[1]
    y= Is[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")
    else:
        print("wrong operand")
    del Is[:2]
    Is[0]=result
print (result)

result = None
Is ='1 + 1 + 1'
Is =Is.split()
while (len(Is) >=3):
    x=Is[0]
    op=Is[1]
    y=Is[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 data type")
        break
    del Is[:2]
    Is[0]=result
    if len(Is) ==2:
        print('wrong operand')
        break
    if len(Is) == 1:
        break
else:
    print("wrong operand")
print (result)
INFO