**记录自己第一次的python38带参函数bug解决
第一次排版不好,见谅
def operator(op1,op2,opfu):
if opfu not in '+=*/':
return -1
elif opfu == '+':
result = op1 + op2
elif opfu == '-':
result = op1 - op2
elif opfu == '*':
result = op1 * op2
elif opfu == '/':
if op2 == 0:
print('Input Errot. Not be 0 !')
result = None
else:
result = op1 / op2
return result
print(operator(op1=10,op2=2,opfu=‘ew’))
def convert(op):
flag = True
for ch in op:
if ch not in ‘1234567890’:
flag = False
break
if flag == True:
return int(op)
else:
return None
if name == ‘main’:
def operation():
while True:
print(‘To exit,Please enter Q’)
opp1 = input('Please Enter The First Number: ')
ch = opp1.strip()[0]
if ch == ‘Q’:
break
op1 = convert(opp1)
if op1 == None:
print(‘Input Error,Please Enter integer.’)
continue
while True:
opfu = input('Please enter 运算符: ')
if opfu in ‘±*/’:
break
else:
print('Input 运算符 Error ')
continue
while True:
op2 = convert(input('Please Enter The second Number: '))
if op2 == None:
print(‘Input Error’)
continue
else:
break
result = operator(op1,op2,opfu)
if result != None:
print(‘计算%d %s %d=%d’ %(op1,opfu,op2,result))
print(‘Quit’)
if name == ‘main’:
operation()