def sum_num(num,dig_num):
var=0
for i in range(dig_num):
var +=int(num(i+1))
if i==(dig_num-1):
print(int(num(i+1)),end='=') #整数乘字符 ,'3'3='333' end='='表示不换行,后面加个 '=' 字符串.
else:
print(int(num(i+1)),end='+')
return var
num=input('请输入要计算的数字:') #字符类型
dig_num=int(input('请输入要计算的次数:'))#整数类型
sum_dig=sum_num(num,dig_num)
print(sum_dig)
网友评论