Question
I am needing a bit of help with this assignment. The asterisk's should form a zigzag line in this code; however they only go in
I am needing a bit of help with this assignment. The asterisk's should form a zigzag line in this code; however they only go in one direction (to the right), and do not change direction to go to the left. I am uncertain what I have done wrong.
Below is the code:
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()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started