View Code of Problem 132

while True:
    try:
        a,b=input().split(' ')
        if not ('.' in a):
            a1=a
            a2=''
        else:
            a1,a2 = a.split('.')
        if not ('.' in b):
            b1=b
            b2=''
        else:
            b1,b2=b.split('.')
        sum1=int(a1)+int(b1)
        l=len(a2)-len(b2)
        if l>0:
            b2+='0'*l
        else:
            a2+='0'*abs(l)
        cnt=0
        if a2=='':
            if b2=='':
                sum2=''
            else:
                sum2=str(int(b2))
        else:
            sum2=str(int(a2)+int(b2))
        if len(sum2)>max(len(a2),len(b2)):
            cnt=1
            sum2=sum2[1:]
        print(sum1+cnt,end='')
        if  sum2!='' and int(sum2)!=0:
            print('.',end='')
            li=list(sum2)
            end=len(li)-1
            while li[end]=='0':
                end-=1
            for i in range(0,end+1):
                print(li[i],end='')
        print()
    except EOFError:
        break

Double click to view unformatted code.


Back to problem 132