Visual Introduction to Python
Learn Python While Programming a Robotic Turtle!
This engaging self-paced course is an excellent introduction to Python programming for beginners.
About The Course
Trainees learn fundamental concepts including Python syntax and code formatting, loops, nested loops, variables, functions, Boolean logic, conditions, lists, and recursion while programming a robotic turtle.
The Visual Intro to Python course uses simple logic and is designed to be visual and fun. However, the programs are written in full Python syntax. This approach demands that trainees pay attention to important details, such as colons, decimal points and parentheses.
This course is a follow-on course to the Computational Thinking course.
Email and Browser
Course Structure and Length
This course is self-paced, and trainees will practice each skill and concept as they go. Automatic feedback is built into the course for both practices and quizzes.
The course is divided into four Units, and each Unit is composed of five Sections. Each Section consists of 7 instructional/practice levels, a quiz, and a master (proficiency) level. Trainees can return to any level or quiz for review.
Trainees will need approximately 80 hands-on hours, based on their ability level, to complete this course. Since the course is self-paced, the amount of time required to complete the course will vary from trainee to trainee. Trainees are responsible for learning both the tutorial content and the skills acquired through practice.
Following is an outline of the course’s units:
- Unit 1: Learn Python syntax and code formatting. Write programs to draw various geometrical objects using for loops and nested loops.
- Unit 2: Learn how to create and use variables, the difference between local and global variables, and how to define and use functions.
- Unit 3: Learn Boolean logic and decision making. Work with Boolean values True and False, and with Boolean operators and, or, not.
- Unit 4: Learn how to create empty and non-empty lists, how to perform important operations with lists, and how to use recursion.
Section 1 (Basic Commands I)
- Create an instance of class NCLab Turtle
- Defaults: line width and color, initial position, grid square size
- Command go(n) to move n steps forward
- Command show() to display the Turtle and its trace
- Commands left(d), right(d) to turn d degrees left or right
- Create a Turtle at an initial position which is different from (0, 0)
- Command color() to change line color
- Names of predefined colors are uppercase
- Command pu() or penup() to lift the pen and stop drawing.
- Command pd() or pendown() to start drawing again.
Section 2 (Basic Commands II)
- Command width() to change line width
- Command hide() to hide the Turtle (but trace will remain visible)
- Command back(n) to make n steps backwards (Turtle is not drawing)
- Command extrude(h) to extrude the Turtle’s trace to thickness h
- Exporting extruded trace as STL file for 3D printing
- Saving STL file in user account
- Publishing STL file on the web and getting shareable link
Section 3 (For-Loop I)
- Python for-loop and its syntax
- Index variable begins at zero and ends with n-1
- Python loop code formatting
- Draw a triangle, square, pentagon and other regular polygons
- Tina’s circle is just a polygon with many edges
- Draw five-pointed star
Section 4 (For-Loop II)
- Use for-loops to draw more complex patterns such as cookie cutters
- Command arc() to draw arcs and circles
- Command height() to change the extrusion height at runtime
- Use it to draw patterns such as a battlement or a regal crown
Section 5 (Nested Loops)
- Code formatting for nested for-loops
- Draw mosaics and other patterns that consist of a polygon rotated multiple times
- Draw patterns such as a sunflower, snowflake or a gear which require more complex nested loops
Section 6 (Index Variable in For-Loops)
- Explain the index variable (loop counter) in a for-loop
- Emphasize that it starts from 0 and ends at n-1
- Draw designs such as steps of increasing height or a spiral
Section 7 (Variables)
- Parametric designs, their advantages
- Use variables to convert fixed designs into parametric
- One, two and three-parameter designs
Section 8 (Functions I)
- Functions as a tool to create reusable functionality
- Defining a function, keyword “def”
- Function code formatting, optional command “return”
- Functions with parameters
- Locality of parameters in the function body
Section 9 (Functions II)
- Defining and using functions with multiple parameters
- Local vs. global variables, function parameters vs. arguments
- Create pendants including the Heart, Celtic knot, and Clover
- Command export() to export Tina’s geometry as a 3D object
- Applying elementary 3D modeling operations to exported Tina geometries
Section 10 (Functions III)
- Command rosol() to convert an XY-plane contour into a rotational solid
- Using functions to create various rotational solids
- Command rosurf() to create rotational surfaces
- Command roshell() to create rotational shells
Section 11 (Random Numbers and Random Walks)
- Importing the random library.
- Generating random integers and real numbers.
- Rescaling random real numbers from the interval (0, 1) to an arbitrary interval (a, b).
- Using random numbers to draw geometries with random elements.
- What are random walks and how to work with them.
- Obtaining current X and Y coordinates of the turtle with the functions getx() and gety().
Section 12 (Conditions)
- Algebraic comparison operators <, >, <=, >=, == and !=.
- The if, if-else, and if-elif-else statements.
- Updating variables with the algebraic operators +=, -=, *= and /=.
- Calculating the minimum and maximum of a sequence of values.
- Initializing multiple variables with the same value at once.
- Use the command ranturn() to turn the turtle by a random angle.
Section 13 (Boolean Logic I)
- Boolean values True and False.
- Boolean variables, expressions, and functions.
- Comparison operators <, >, <=, >=, ==, != evaluate to True or False.
- The if and elif statements expect True or False.
- Boolean operators not, and, or and their truth tables.
- Parentheses are needed to ensure correct evaluation of complex Boolean expressions.
Section 14 (Boolean Logic II)
- Use the sensor oncolor() to check for a color on the ground.
- This sensor is a Boolean function which returns either True or False.
- Calling oncolor() will check for any color on the ground.
- With a particular color, such as oncolor(CYAN), the sensor will check for that color.
- Practice working with conditions and Boolean logic.
Section 15 (While Loop)
- The while loop, difference vs. the for loop.
- Use the while loop with Boolean values, variables, expressions and functions.
- RGB colors and RGB color codes.
- New sensor colorprobe() which allows the turtle to sample colors on the ground.
- Python keyword None.
- Absence of do-while loops in Python.
- Infinite while loop and when it is useful.
- Keyword break which can be used to terminate any loop.
- Solve a number of tasks to practice the while loop and Boolean logic.
Section 16 (Programming Practice I)
- Python programming practice with emphasis on line-following algorithms of robotics.
- Practice for and while loops, conditions, their combinations, and the break statement.
- Review the difference between function parameters and arguments.
- Define and use functions with default parameter values.
- Integer division operator //.
- Use while loops of the form while not done.
Section 17 (Programming Practice II)
- Python programming practice with emphasis on additional robotics algorithms.
- Practice Boolean logic and using functions with default parameter values.
- What is a LIDAR sensor and where it is used.
- Use a LIDAR to detect randomly placed objects.
- Use a LIDAR to measure the size of objects.
- Use a LIDAR to guide the turtle through unknown mazes.
Section 18 (Python Lists I)
- Create empty and nonempty lists.
- Obtain the length of a list.
- Append items to a list.
- Access list items via their indices.
- Using negative indices.
- Indices of list items start from zero.
- Insert items into lists.
- Pop (remove and return) items from lists.
- Delete list items.
- Check if a list is non-empty.
- Parse lists with the for loop.
Section 19 (Python Lists II)
- Use lists to simplify algorithms.
- Check for given items in lists.
- Count the occurrences of given items in lists.
- Calculate the maximum and minimum of a list of numbers.
- Add up all numbers in a list.
- Reverse and sort lists.
- Add lists and multiply them with integers.
- Slice lists.
- Copy and reverse lists via slicing.
Section 20 (Recursion)
- Understand what recursion is and when it should be used.
- Understand the importance of stopping condition.
- Always make the recursive call after a stopping condition.
- Typical mistakes in recursive algorithms.
- Solve problems using recursion.
- Use multiple recursive commands to solve a task.
- Use recursion to draw fractals including the Koch’s Snowflake and Fractal Tree.