输入2,5 求2+22+222+2222+22222的值

s1 = 0

def fun(x, y):
    global s1
    a = 0
    for i in range(1,y+1):
        print(i)
        if i == 1:
            a = x
            s1 += a
            i += 1
        elif 1 < i < y:
            a += x * 10 ** (i-1)
            s1 += a
            i += 1
        elif i == y:
            a += x * 10 ** (i-1)
            s1 += a
            break
    return s1

print(fun(2,5))

你可能感兴趣的:(输入2,5 求2+22+222+2222+22222的值)