View Code of Problem 132

from decimal import Decimal
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
        sum2=str(int(a2)+int(b2))
        if len(sum2)>max(len(a2),len(b2)):
            cnt=1
            sum2=sum2[1:]
        print(sum1+cnt,end='')
        if  int(sum2)!=0:
            print('.'+sum2,end='')
        print()
    except:
        break

Double click to view unformatted code.


Back to problem 132