-
Iamxiaoq
def my_add(s):
s = str(s)
if len(s) == 1 or not s.isdigit():
return
nums = map(lambda x:int(x), s)
total = sum(nums)
print("{}={}".format("+".join(s), total))
my_add(total)
s = input("input a number:")
my_add(s)
-
phpmadman
function cal(num){
if(num>=10){
var str=num+"";
var num=0;
var arr=str.split("");
for(var i=0;i<arr.length;i++){
num+=arr[i]-0;
if(i<arr.length-1){
document.write(arr[i]+"+")
}else{
document.write(arr[i]+"="+num+"<br/>")
}
}
return cal(num);
}else{
return "OK";
}
}
var a=prompt("请输入一个数字","在这里输入数字");
cal(a);
-
cnaz
while num > 0 :
digit= num % 10
num= num//10
if num > 1:
print (digit, end =" ""+"" ")
else:
print (digit, end =" ")
digit_sum += digit
print ("=",digit_sum, end = " ")
print ("")
while digit_sum >10:
digit= digit_sum % 10
digit_sum= digit_sum//10
if digit_sum > 1:
print (digit, end =" ""+"" ")
else:
print (digit, end =" ")
digit_sum += digit
print ("=",digit_sum, end = " ")
print ("")我是这样做的,但是第二个循环出了问题,最后的运算结果不对。但是一修改就很容易出现无限循环的情况
-
qq_迟来的秋天_04009602
def my_fun(number=0):
return sum(map(int, list(str(number))))
-
qq_迟来的秋天_04009602
python实现方式:def my_fun(number=0):
return sum([int(i) for i in list(str(number))])
-
Nelson_Zhao
def addnum(number):
nums = map(lambda x: x, number)
result = reduce(lambda x, y: int(x) + int(y), nums)
print ' + '.join(nums) + ' = ' + str(result)
if __name__ == "__main__":
addnum(raw_input('Please input> '))