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)
result = None
Is ='1 + 1 + 1 + 1'
Is =Is.split()
def check_float(data):
try:
float(data)
return True
except ValueError:
print("invalid input")
return False
while (len(Is) >=3):
x=Is[0]
op=Is[1]
y=Is[2]
if check_float(x) and check_float(y):
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)