Python Forum

Full Version: zigzag example
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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:

********
********
********
********
********
********
********
********
********
Hint, you will require a space in your code
'' is not ' '
[video=youtube]https://youtu.be/scyg0ypvAj8 [/video]
(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.
Is line 7 supposed to be printing spaces? I don't see any spaces on that line.
Yes. Line 7 should have one space in the first quotes.
(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!
Line 7 print(' ' * indent, end='')
(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!
Pages: 1 2