此代码中的间距不正确

时间:2017-10-01 05:20:56

标签: python

num = int(input("Enter a number: "))

count1 = 0

if num <= 0 or num > 26:

print("Invalid input, program terminates.")

else:


while count1 < num:

count2 = 0

while count2 < count1:

print(chr(ord('A')+count2),end="")

count2 += 1

print("")

count1 += 1

while count1 > 0:

count2 = 0

while count2 < count1:

print(chr(ord('A')+count2),end="")

count2 += 1

print("")

count1 -= 1

输出

A
AB
ABC
ABCD
ABCDE
ABCD
ABC
AB
A

1 个答案:

答案 0 :(得分:0)

num = int(input("Enter a number: ")) count1 = 0 if num <= 0 or num > 26:
    print("Invalid input, program terminates.") else:
    while count1 < num:
        count2 = 0
        while count2 < count1:
            print(chr(ord('A')+count2),end="")
            count2 += 1
        print("")
        count1 += 1
    while count1 > 0:
        count2 = 0
        while count2 < count1:
            print(chr(ord('A')+count2),end="")
            count2 += 1
        print("")
        count1 -= 1

享受! 附:如果你只是学习如何编码,复制粘贴不会教你什么:)

关于缩进的好文章:http://www.peachpit.com/articles/article.aspx?p=1312792&seqNum=3