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
#2
Hint, you will require a space in your code
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
'' is not ' '
Reply
#4
[video=youtube]https://youtu.be/scyg0ypvAj8 [/video]
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#5
(May-03-2020, 03:26 AM)deanhystad Wrote: '' is not ' '

I initially used " instead of '', because if I used " I get an EOL syntax error.
Reply
#6
Is line 7 supposed to be printing spaces? I don't see any spaces on that line.
Reply
#7
Yes. Line 7 should have one space in the first quotes.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#8
(May-03-2020, 02:18 AM)menator01 Wrote: Hint, you will require a space in your code

hello,

I am a total newb and just started learning (self-teaching Python). I, too, am having the same problem as the initial poster in here and I read your hint about a space in Line 7 but cannot, for the life in me, get it to work. I've added, taken away, and even used quotes rather than apostrophes (even though I know that's not proper coding). I've run through the debugger and looked step by step but cannot find where I'm missing a space. I couldn't find any hints after further web searches as well. May I ask for another hint, please sir (totally feel like Oliver Twist of the python world asking that)? Smile

Thank you for your time and help!
Reply
#9
Line 7 print(' ' * indent, end='')
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#10
(Jul-06-2020, 12:46 AM)menator01 Wrote: Line 7 print(' ' * indent, end='')

You are awesome. I didn't put a space between * and indent....I think that was my issue! I really appreciate your help!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An important question is how to create a zigzag in price data? epsilon 0 1,312 Nov-18-2020, 08:06 PM
Last Post: epsilon
  movement in a zigzag in a 2d array ShakeDat53 1 2,860 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