强文#计划解释了累计相同的数字添加,但问题在于 回答额外的零点
a = int(input("enter the number of units you want")) #number of times
b = input("Enter the digit") #actual integer
ans = str(0)
z = 0
for i in range(1,a+1): #loop for number of integers
for j in range(1): #loop for repitation of integer
ans=b+ans
z = int(ans)+int(z)
print("Ans is"+" "+str(z))
答案 0 :(得分:0)
你几乎是正确的。不需要range(1)
循环,ans
应该从0开始为空。
a = int(input("enter the number of units you want")) #number of times
b = input("Enter the digit") #actual integer
ans = ""
z = 0
for i in range(1,a+1): #loop for number of integers
ans=str(b)+ans
z = int(ans)+int(z)
print("Ans is"+" "+str(z))
答案 1 :(得分:0)
假设,对于数字6输入5次,您需要输出:
"66666"
然后只需更改
ans = str(0) to ans = "" or ans = ''
否则,如果输出应为30
,则需要:
...
b = int(input(...))
ans = 0
...