Sum the digits of a number

后端 未结 18 2306
抹茶落季
抹茶落季 2020-11-22 10:52

If I want to find the sum of the digits of a number, i.e.:

  • Input: 932
  • Output: 14, which is (9 + 3 + 2)
18条回答
  •  半阙折子戏
    2020-11-22 11:21

    n = str(input("Enter the number\n"))
    
    list1 = []
    
    for each_number in n:
    
            list1.append(int(each_number))
    
    print(sum(list1))
    

提交回复
热议问题