小编snu*_*101的帖子

在Python 3中打印1-100中的数字作为单词

List_of_numbers1to19 = ['one', 'two', 'three', 'four', 'five', 'six', 'seven',
                   'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen',
                   'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen',
                   'nineteen']
List_of_numbers1to9 = List_of_numbers1to19[0:9]
List_of_numberstens = ['twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy',
                       'eighty', 'ninety']

for i in List_of_numbers1to19:
    print(i)
list_of_numbers21to99 = []
count = 19
tens_count = 0
for j in List_of_numberstens:
    for k in List_of_numbers1to9:
        if tens_count%10 == 0:
            #should print an iteration of List_of_numberstens
            tens_count +=1
        tens_count +=1
        print(j, k)
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,这变得很乱:P很抱歉.基本上我正在尝试使用具有不同索引的三个不同的for循环来打印它们.我已经尝试过对列表进行切片并为列表编制索引,但我仍然将输出的数字乘以10作为完整列表List_of_numberstens.

我觉得我在这里要做的很清楚.

在此先感谢您的帮助!

python numbers python-3.x

-1
推荐指数
1
解决办法
590
查看次数

标签 统计

numbers ×1

python ×1

python-3.x ×1