Software tools needed: web browser and Python programming environment.
Our first programs will be using Python. The laptops in 1001E HN have Python installed. To install Python on your home machine, see Lab 0 for details.
We will be using the IDLE programming environment for Python, since it is very simple and comes with all distributions of Python. It has similar functionality to the editors used for technical interviews, and we will also use it for our weekly check-ins ("code reviews"). Working with IDLE for your homework is good practice for our code reviews and for future technical interviews.
To launch IDLE:
idle
(followed by an enter/return).print("Hello, World!")
You should see: Hello, World! echoed on the window.
Instead of using the shell window (where we can try things immediately), let's use a text window, where we can save our program for later and submit it to Gradescope (this is the basis of the first program).
"""
Name: ...your name here...
Email: ...your email here...
Date: February 3, 2025
This program prints hello
"""
print("Hello, ...your name here...")
This course will use the online Gradescope system for submitting work electronically.
Homework 01: Hello!.
Now that you have just submitted your first program, let's try some other Python commands. Here's a quick demo (click the triangle to run the program):
A quick overview of the above program:
import turtle loads in the built-in turtle graphics drawing package. It's part of all versions of Python but, to keep programs small, is not included unless you explicitly import it. In addition to built-in packages, there are many others that have been written to make Python more useful. We will use both kinds as the semester progresses.
thomasH = turtle.Turtle() creates a turtle object called thomasH (you can call your turtles almost any combination of letters (and underscores and numbers)-- we used a name starting with "t" since turtle starts with "t").
for i in range(4): is the first part of a for-loop that will repeat the commands indented beneath it 4 times.
Let's write the same program in IDLE:
File > New File).
import turtle
thomasH = turtle.Turtle()
for i in range(4):
thomasH.forward(150)
thomasH.left(90)
import turtle
wn = turtle.Screen()
thomasH = turtle.Turtle()
for i in range(4):
thomasH.forward(150)
thomasH.left(90)
wn.exitonclick()
File > Save). Run > Run Module from the Run menu).
"""
Name: ...your name here...
Email: ...your email here...
Date: Feburary 3, 2025
This program draws an triangle.
"""
Run your program after editing to make sure you do not have any typos.
Assignments. From the list, choose Program 02: Triangle.
In the file upload, drag the .py file you just created and ran, and click "Submit".
To review, we introduced the turtle commands:
There are many more turtle commands. Over the next couple of classes, we will learn more. In addition to the ones that control movement, you can also change the color of the turtle, change the size of the drawing pen, and change the background color (by making a window or screen object, and changing its color).
Note: Your homework programs are graded on a cloud server without a graphics window. As a result, your program is tested using an alternative non-graphics-based turtle package that supports the following subset of turtle commands:
backward, color, colormode, forward, goto, hideturtle, home, left, pendown,
penup, pensize, right, shape, showturtle, speed, stamp
Please use only these turtle commands in your homework programs.
You can start working on this week's homework. The Homework page has problem descriptions, suggested reading, and due dates next to each problem.