标签:pen NPU 一个 app ret sum str end col
1 a = eval(input(‘请输入一个数字:‘)) 2 n = eval(input(‘请输入次数n:‘)) 3 sum = [] 4 sum2 = 0 5 s1 = 0 6 i = 0 7 while i <= n-1: 8 s1 =s1+(a*(10**i)) 9 sum.append(s1) 10 11 i += 1 12 sum1 = [str(i) for i in sum] 13 for j in sum: 14 sum2 += j 15 print(‘+‘.join(sum1),‘=‘,sum2) 16 17 2)看了大神的写法 18 a =input(‘输入数字>>>:‘) 19 count = int(input(‘几个数字相加>>>:‘)) 20 ret = [] 21 for i in range(1,count+1): 22 ret.append(int(a*i)) 23 print(ret[i-1],end=‘ ‘) 24 print(‘\n结果为:‘,sum(ret))
标签:pen NPU 一个 app ret sum str end col
原文地址:https://www.cnblogs.com/reaix/p/12432440.html