Below is the code. The line is supposed to go in one direction and then another (zigzag).While
Question:
Below is the code. The line is supposed to go in one direction and then another (zigzag).While I am able to get the asterisk's to go in one direction, I am unable to figure out what I did wrong to have them go back in the opposite direction based on the instructions. In other words, they will go to the right but do not change direction:
while True:
print ('Enter an integer between 5 and 25.')
try:
userNum = int(input())
except ValueError:
print ('You must enter an integer!')
if userNum < 5:
continue
elif userNum > 25:
continue
else:
break
import time, sys
indent = 0
indentIncreasing = True
try:
while True: # The main program loop.
if indent == 0:
print ('' * indent, end='')
print ('*' * userNum)
indent = indent + 1
print (' ' * indent, end ='')
print ('*' * userNum)
time.sleep(0.1) # Pause for 1/10 of a second.
if indentIncreasing == False:# Increase the number of spaces:
indent = indent - 1
if indent == 0:
print (' ' * indent, end='')
print ('*' * userNum)
indentIncreasing = True
indent = indent + 1
else:
indent = indent +1
if indent == 20:
print (' ' * indent, end='')
print ('*' * userNum)
increasingIndent = False
indent = indent - 1
else:#Decrease the number of spaces:
indent = indent - 1
if indent == 0: #Change direction
print (' ' * indent, end='')
print ('*' * userNum)
indentIncreasing = True
except KeyboardInterrupt:
sys.exit()
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill