PTA Python Exercises (22)

Chapter 5-3 Four arithmetic operations (implemented by dictionary)

a=int(input())
b=input()
c=int(input())
if(c==0):
    print('divided by zero')
else:
    jisuan={'+':a+c,'-':a-c,'*':a*c,'/':a/c}
    r=jisuan[b]
    print('%.2f'%(r))

Write in the dictionary and then call

Guess you like

Origin www.cnblogs.com/echoDetected/p/12757454.html