zigzag example - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: zigzag example (/thread-26474.html) Pages:
1
2
|
zigzag example - shabux - May-03-2020 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: ******** ******** ******** ******** ******** ******** ******** ******** ******** RE: zigzag example - menator01 - May-03-2020 Hint, you will require a space in your code RE: zigzag example - deanhystad - May-03-2020 '' is not ' ' RE: zigzag example - menator01 - May-03-2020 [video=youtube]https://youtu.be/scyg0ypvAj8 [/video] RE: zigzag example - shabux - May-03-2020 (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. RE: zigzag example - bowlofred - May-04-2020 Is line 7 supposed to be printing spaces? I don't see any spaces on that line. RE: zigzag example - menator01 - May-04-2020 Yes. Line 7 should have one space in the first quotes. RE: zigzag example - floppywalking - Jul-06-2020 (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)? Thank you for your time and help! RE: zigzag example - menator01 - Jul-06-2020 Line 7 print(' ' * indent, end='')
RE: zigzag example - floppywalking - Jul-11-2020 (Jul-06-2020, 12:46 AM)menator01 Wrote: Line 7 You are awesome. I didn't put a space between * and indent....I think that was my issue! I really appreciate your help! |