Py学习  »  Python

如何在python中将int打印为words seq

Martin • 5 年前 • 1477 次点击  

我有一张写数字的桌子

table = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']

用户应该在输入中写入一个数字:

number = input()

现在我需要以这种方式创建函数打印单词表示(例如,对于242):

> 242 - two four two

我写了那段代码,但它不能正常工作(索引或打印列表的问题)。我怎样才能用最简单的方式来实现这个功能呢?

我的密码:

table=['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
number = input()

for x in range(len(table)):
    print(table[number[x]], end=' ')
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/47932
 
1477 次点击  
文章 [ 1 ]  |  最新文章 5 年前