摘要
很基础的题目,考察对于数据存储的知识
原题
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Input Specification:
Each input file contains one test case. Each case occupies one line which contains an N (≤10100).
Output Specification:
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
one five
题目意思
输入一个数,将数的每一位加起来得到一个sum,将这个sum用英文逐位输出
思路
输入的是一个字符串,用迭代器把每一位取出来存进列表,再用sum对列表求和并逐位存进列表,最后制作一个字母表遍历输出即可
Python代码
words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
num_list = [i for i in input()] # 输入数字
ans_list = [i for i in str(sum(int(n) for n in num_list))] # 求和
print(" ".join(words[int(i)] for i in ans_list))