Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
zigzag example
#1
windows 10, python 3.8

Trying to do zigzag example but not getting right result. I type following code, which I think is identical to the lesson's:

import time, sys
indent = 0 # How many spaces to indent.
indentIncreasing = True #Whether the indentation is increasing or not.

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:
                #Change direction:
                indentIncreasing = False

        else:
            #Decrease the number of spaces:
            indent = indent - 1 
            if indent == 0:
                #Change direction:
                indentIncreasing = True

except KeyboardInterrupt:
    sys.exit()
But instead of getting a looping result like this:

    ********
   ********
  ********
 ********
********
 ********
  ********
   ********
    ********
...I am instead getting a looping result like this:

********
********
********
********
********
********
********
********
********
Reply


Messages In This Thread
zigzag example - by shabux - May-03-2020, 02:09 AM
RE: zigzag example - by menator01 - May-03-2020, 02:18 AM
RE: zigzag example - by floppywalking - Jul-06-2020, 12:39 AM
RE: zigzag example - by deanhystad - May-03-2020, 03:26 AM
RE: zigzag example - by shabux - May-03-2020, 11:43 PM
RE: zigzag example - by menator01 - May-03-2020, 05:11 AM
RE: zigzag example - by bowlofred - May-04-2020, 12:06 AM
RE: zigzag example - by menator01 - May-04-2020, 12:32 AM
RE: zigzag example - by menator01 - Jul-06-2020, 12:46 AM
RE: zigzag example - by floppywalking - Jul-11-2020, 11:11 PM
RE: zigzag example - by bowlofred - Jul-11-2020, 11:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  An important question is how to create a zigzag in price data? epsilon 0 1,326 Nov-18-2020, 08:06 PM
Last Post: epsilon
  movement in a zigzag in a 2d array ShakeDat53 1 2,883 Aug-17-2018, 08:22 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020