试图打印一个字母金字塔

时间:2015-06-03 15:00:38

标签: python python-2.7

尝试打印这样的内容:

A
AB
ABC
ABCD
ABCDE

我试过了:

    e = 0
    for e in range(1,4):
    for f in range(e,0,-1):
        print "A B C D"
    print " "

但它没有用。任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:2)

abc = ["A","B","C","D","E"]
toprint=""
for x in range(len(abc)):
    toprint += abc[x]
    print(toprint)

这就是你如何做你想做的事情

或其他版本

abc = "ABCDE "

for x in range(1,len(abc)):
    print(abc[:x])

答案 1 :(得分:0)

module uart (inputs, outputs, etc)