Chapter 3-12 seeking integer digits and the sum of the digits (15 points) [python]

对于给定的正整数N,求它的位数及其各位数字之和。

输入格式:
输入在一行中给出一个不超过109
​​ 的正整数N。

输出格式:
在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。

输入样例:
321

      
    
输出样例:
3 6
str = input()
num = 0
for index in str:
    num = num  + int(index)
print("%d %d"%(len(str),num))
exit(0)
Published 363 original articles · won praise 95 · views 180 000 +

Guess you like

Origin blog.csdn.net/qq_43788669/article/details/105395153