我很难弄清楚为什么我的代码无法正常工作。 我的输出看起来像一堆没有做任何事情的星号,而不是适当的锯齿形。
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()
我的输出:
所需的输出: