自动化无聊的东西第 3 章:之字形练习

我很难弄清楚为什么我的代码无法正常工作。 我的输出看起来像一堆没有做任何事情的星号,而不是适当的锯齿形。

import time,sys

indent = 0 # How many spaces to indent.
indentIncreasing = True #Whether or not the indent increases

try:
    while True:
        #The main program loop
        print(' ' * indent,end='')
        print('********')
        time.sleep(0.1) # Pause for 1/10 of a second.
    
    if indentIncreasing:
        
        #Increase the number of spaces:
        indent = indent + 1
        if indent == 20:
            indentIncreasing = False
       # Change direction:
        else:
            #decrease the number of spaces:
            indent = indent - 1
            if indent == 0:
                #Change direction:
                indentIncreasing = True
except KeyboardInterrupt:
    sys.exit() 

我的输出:

自动化无聊的东西第 3 章:之字形练习

所需的输出:

自动化无聊的东西第 3 章:之字形练习

HWSGCH 回答:自动化无聊的东西第 3 章:之字形练习

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/17588.html

大家都在问