ZigZag • Beginner Python Project

Table of Contents

Let’s learn some Python!

Want an easy python program to get started? Here’s zigzag.

This program is from Automate The Boring Stuff With Python Chapter 3, under A Short Program: Zigzag.

Welcome to my third study session to learn Python Programming! The video above covers the entire process of copying the zig zag program from Automate The Boring Stuff With Python.

See Built-in Functions, Time access and conversions and What does end=’ ‘ exactly do?

1. Program

See the complete program below, feel free to copy this.

import time,sys 
indent = 0 # Amount of spaces to indent
indentIncreasing = True # Increase or not

try:
    while True: # Main program loop
        print(' ' * indent, end='')
        print('********')
        time.sleep(0.1) # Pause for 1/10

        if indentIncreasing:
            # Increase number of spaces
            indent = indent + 1
            if indent == 20:
                # Change direction
                indentIncreasing = False
        
        else:
            # Decrease number if spaces
            indent = indent - 1
            if indent == 0:
                # Change direction (again)
                indentIncreasing = True
except KeyboardInterrupt:
    sys.exit()

For a full writeup and breakdown of each stage in the program, see the official A Short Program: Zigzag.

2. Reflection

This was a really quick and easy program to copy and deconstruct, it’s worth doing it yourself.

I learnt about the time module and I’m getting more comfortable looking up modules from the standard library. Thank goodness for great online documentation!

It’s also good to see the try/except statement in use again. It’s a pretty straightforward statement in Python I’ve got my head around.

I still don’t have a complete grasp on the line print(' ' * indent, end='') – even after reading up about the print function again, it hasn’t really clicked for me just yet.

This short program reminded me of the start of CS50x, a fantastic computer science course! I started it and failed to program, so I’ll be going back to that in the future. This program and learning Python, in general, is giving me the confidence to do it!

This is Day 27 of #100DaysOfHacking, subscribe to the newsletter for updates and if you have feedback, message me via Twitter. Happy Hacking.

About The Author
Ashley Ball

Ashley Ball

“Learn, create, share, repeat.” • IT teacher, former web designer, learning #cybersec • Road to #100DaysOfHacking
Share This Article
Share on linkedin
LinkedIn
Share on twitter
Twitter
Share on facebook
Facebook
Share on whatsapp
WhatsApp
Share on email
Email

Monthly Newsletter

Learn about design, web tech and cyber security.

Leave A Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More Content

Monthly Newsletter

Learn about design, web tech and cyber security.

This site uses cookies and other tracking technologies to assist with navigation, monitor site usage and web traffic, assist with our promotional and marketing efforts, and customize and improve our services, as set out in our privacy policy