Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students explore these related Algorithms questions