All students registered by Friday, August 22, are sent a Gradescope registration invitation to the email on record on their Brightspace account. If you did not receive the email or would like to use a different account, fill in the form on Brightspace. Include that you not receive a Gradescope invitation, your preferred email, and your EmpID. We will manually generate an invitation. As a default, we use your name as it appears in Brightspace/CUNYFirst (to update CUNYFirst, see changing your personal information). If you prefer a different name for Gradescope, include it, and we will update the Gradescope registration.
Learning programming is like learning a foreign language: you will learn more (with less work) if you practice every day. Some of the programs below are easy; some will take more time. We suggest you set aside a block of time most days to work on programming and the course.
The programs build on the concepts and code developed during lecture, lab, and through the reading. Mastery of material is assessed via
The majority of the programs this semester are written in Python (see Lab 1 for getting started with Python); it is noted below when other formats or languages are used. For Python programs, the autograder expects a .py
file, using only the specified libraries, and does not accept iPython/Jupyter notebooks. Since all assignments are designed to be uploaded as a single file, the autograder is set up for direct file upload instead of Github. If submitting directly (drop-and-drag onto the webpage), the file name is flexible but must have the extension .py
, unless otherwise noted.
Also, to receive full credit, the code should be compatible with Python 3.10 (the default for the Gradescope autograders).
To get full credit for a program, the file must include in the opening comment:
For example, for the student, Thomas Hunter, his first program might be:
"""
Name: Thomas Hunter
Email: thomas.hunter1870@hunter.cuny.edu
Date: September 1, 2025
This program prints: Hello, Thomas Hunter
"""
print("Hello, Thomas Hunter")
For each program, the upper right hand side of the description contains the due date, suggested reading, and, when applicable, the available libraries. When testing your Python programs, the autograder uses Python 3.10 and has available the libraries listed. If the available libraries is none, no additional libraries are used (e.g. no import
statement is needed in your program).
You may submit your assignments up to three weeks before the due date and are encouraged to work ahead. To receive credit, assignments must be submitted by the deadline to Gradescope. For more information on using Gradescope, see Lab 1. Since Gradescope gives limited feedback, run your program first locally (on your computer or a lab computer) where the compiler messages will pinpoint errors and help debug your code. For example, if Gradescope gives you a "The autograder failed to execute..." error, it means your program has an error (in this case, it's usually the file contains non-Python commands.). The local Python compiler will give the line of your file with the error, where Gradescope will only say that there's a general problem. For more information on installing Python on your computer, see the installation guides.
Due Date: 5pm, Tuesday, September 2
Reading: Chapter 1 & Lab 1
Available Libraries: none
Hello
Write a program that prints Hello
followed by your name to the screen. For example, if your name is Thomas Hunter
, when your program is run, it would print:
Hello, Thomas Hunter
Due Date: 5pm, Wednesday, September 3
Reading: Chapter 4 & Lab 1
Available Libraries: turtle
Triangle
Write a program that draws a triangle using the turtle
library.
Note: Whenever submitting a turtle program, choose a name for your file that is not turtle.py.
When executing the import turtle
statement, the computer first looks in the folder where the file is saved for the turtle module and then in the libraries (and other places on the path). If you name your file turtle.py, it thinks the module is itself, causing all kinds of errors. To avoid this, name your program something like myTurtle.py or program2.py.
Due Date: 5pm, Thursday, September 4
Reading: Chapter 4 & Lab 1
Available Libraries: turtle
Turtle Drawing
Write a program that implements the incomplete code (start right from the red spot and return to there). The initial part of the code is provided if you like. The colors are green, blue, cyan, and red, respectively.
"""
Your Name
Your Email
"""
import turtle
t = turtle.Turtle()
t.pensize(5)
t.shape("circle")
"""
TODO: finish the rest of the program
Hint: The distance for a long line is 300.
The distance for a short line is 100.
"""
The result should look as follows:
Due Date: 5pm, Friday, September 5
Reading: Chapter 1 & Lab 1
Available Libraries: none
Multiple Greetings
Write a program that will print Welcome! multiple times. The number of times depends on your EmplID number. Take the last 2 digits of your EmplID number and add 10. For example, if your EmplID ends in 13, the number of times you repeat the message is 13+10 = 23.
For example, with an EmplID ending in 02, you would repeat the message 12 times:
Welcome!
Welcome!
Welcome!
Welcome!
Welcome!
Welcome!
Welcome!
Welcome!
Welcome!
Welcome!
Welcome!
Welcome!
Due Date: 5pm, Tuesday, September 9
Reading: Chapter 4 & Lab 1
Available Libraries: turtle
Flower
Write a program that implements the pseudocode ("informal high-level description of the operating principle of a computer program or other algorithm") below:
Change the pen to blue.
Repeat 50 times:
Repeat 5 times:
Walk forward 100 steps.
Turn right 72 degrees.
Turn right 70 degrees.
Your output should look like this:
Due Date: 5pm, Wednesday, September 10
Reading: Chapter 2 & Lab 2
Available Libraries: none
Upper & Lower
Using the string commands introduced in Lab 2, write a Python program that prompts the user for a message, and then prints the message, the message in lower case letters, and the message in upper case letters.
A sample run of your program should look like:
Enter a message: Mihi cura futuri
Mihi cura futuri
mihi cura futuri
MIHI CURA FUTURI
Another run:
Enter a message: I love Python!
I love Python!
i love python!
I LOVE PYTHON!
Hint: Your program should be able to take any phrase the user enters and prints it, prints it in lower case letters, and prints it in upper case letters. To do that, you need to store the phrase in a variable and print variations of the stored variable. See "More Useful String Methods" in Lab 2.
Due Date: 5pm, Thursday, September 11
Reading: Chapter 2 & Lab 2
Available Libraries: none
Lowercase ASCII
Write a program that prompts the user to enter a phrase, converts the phrase to lowercase, and then prints out each lowercase character and its corresponding ASCII code.
A sample run of your program should look like:
Enter a phrase: abc
a 97
b 98
c 99
And another sample run:
Enter a phrase: ABC
a 97
b 98
c 99
Another run, with a longer phrase:
Enter a phrase: I love Python!
i 105
32
l 108
o 111
v 118
e 101
32
p 112
y 121
t 116
h 104
o 111
n 110
! 33
Hint: The first step is to ask the user for input (see Section 2 of Lab 2). If c is a character, ord(c)
returns its ASCII code. For example, if c is 'i', then ord(c)
returns 105. See Lab 2 for more on ASCII and characters.
Due Date: 5pm, Friday, September 12
Reading: Chapter 2 & Lab 2
Available Libraries: none
Counting by 17's
Write a program that prints out the numbers from 850 to 1700, counting by seventeens.
The output of your program should be:
850
867
884
901
918
935
952
969
986
1003
1020
1037
1054
1071
1088
1105
1122
1139
1156
1173
1190
1207
1224
1241
1258
1275
1292
1309
1326
1343
1360
1377
1394
1411
1428
1445
1462
1479
1496
1513
1530
1547
1564
1581
1598
1615
1632
1649
1666
1683
1700
Due Date: 5pm, Tuesday, September 16
Reading: Chapter 4 & Lab 2
Available Libraries: turtle
Expanding Hexadecagon
Write a program, using the turtle library, that implements the pseudocode below:
For i = 60, 62, 64, 26, ... ,110:
Turn pen red.
Walk forward i steps.
Turn left 45 degrees.
Turn pen blue.
Walk forward i steps
Turn right 90 degrees
Your output should look similar to:
Hint: See examples of range(start,stop,step)
in Section 4 of Lab 2.
Due Date: 5pm, Wednesday, September 17
Reading: Chapter 2 & Lab 2
Available Libraries: none
Acronyms
Write a program that prompts the user for a phrase and creates an acronym, consisting of the first letters of each word, in uppercase.
To approach a problem, it is useful to break it into steps:
Now translate the above pseudocode (informal but detailed description of the steps in a program) into python and test that your program works as follows:
Enter a phrase: City University New York
Your phrase in capital letters: CITY UNIVERSITY NEW YORK
Acronym: CUNY
And another run:
Enter a phrase: Hunter College
Your phrase in capital letters: HUNTER COLLEGE
Acronym: HC
Hint: See examples of looping throught strings in Section 4 of Lab 2.
Due Date: 5pm, Thursday, September 18
Reading: Chapter 4 & Lab 3
Available Libraries: turtle
Shades of Blue
Modify the program from Lab 3 to show the shades of blue.
Your output should look similar to:
Due Date: 5pm, Friday, September 19
Reading: Chapter 2 & Lab 2
Available Libraries: none
Word Count
Write a program that asks the user for a phrase, and prints out the number of words in the phrase. Your program should repeat this for 4 more phrases (a total of 5 phrases):
The output of your program should be:
Enter phrase: This is my letter to the World
7
Enter phrase: That never wrote to Me-
5
Enter phrase: The simple News that Nature told-
6
Enter phrase: With tender Majesty
3
Enter phrase: Emily Dickinson
2
Due Date: 5pm, Thursday, September 25
Reading: Chapter 2, Chapter 4 & Lab 3
Available Libraries: turtle
Color Stamps
Write a program that asks the user for a color in hexadecimal notation, moves a turtle forward 20 steps, and then stamps out a turtle shape that color. Your program should repeat this for 4 more colors in hexadecimal notation (a total of 5 turtle stamps and moves forward).
For example, if you ran your program and the user entered:
Enter color (as hex): #0000FF
Enter color (as hex): #0000B8
Enter color (as hex): #000087
Enter color (as hex): #000043
Enter color (as hex): #000011
The output would be:
Due Date: 5pm, Friday, September 26
Reading: Section 2.8, Chapter 4, Lab 2 & Lab 4
Available Libraries: turtle
Turning Turtle
Write a program that asks the user for 5 whole (integer) numbers. For each number, turn the turtle left the degrees entered and then the turtle should move forward 100.
A sample run of your program should look like:
Enter a number: 270
Enter a number: 100
Enter a number: 190
Enter a number: 200
Enter a number: 80
and the output should look similar to:
Due Date: 5pm, Monday, September 29
Reading: Lecture 2 & Chapter 2
Available Libraries: none
Caesar Cipher
(The cipher disk above shifts 'A' to 'N', 'B' to 'O', ... 'Z' to 'M', or a shift of 13.
From secretcodebreaker.com)
Write a program that prompts the user to enter a word and then prints out the word with each letter shifted right by 13. That is, 'a' becomes 'n', 'b' becomes 'o', ... 'y' becomes 'l', and 'z' becomes 'm'.
Assume that all inputted words are in lower case letters: 'a',...,'z'.
A sample run of your program should look like:
Enter an all-small-letter string: zebra
Enter a non-negative int to shift: 13
Encoded string: mroen
Here is another sample run of your program.
Enter an all-small-letter string: owqfka
Enter a non-negative int to shift: 6
Encoded string: ucwlqg
Hint: See the example programs from Lecture 2.
Due Date: 5pm, Tuesday, September 30
Reading: Lecture 3, Section 9.7 & Lab 2
Available Libraries: none
Slicing Loop
Implement the following piece of pseudocode as a complete program:1. Prompt the user to enter a string and call it s. 2. Let ls be the length of s. 3. For i in 0, 1, ..., ls-1: 4. Print s[:i] 5. For i in 0, 1, ..., ls-1: 6. Print s[i:] 5. Print a closing statement
A sample run of your program should look like:
Enter string: a man a plan a canal panama
which would output:
a
a
a m
a ma
a man
a man
a man a
a man a
a man a p
a man a pl
a man a pla
a man a plan
a man a plan
a man a plan a
a man a plan a
a man a plan a c
a man a plan a ca
a man a plan a can
a man a plan a cana
a man a plan a canal
a man a plan a canal
a man a plan a canal p
a man a plan a canal pa
a man a plan a canal pan
a man a plan a canal pana
a man a plan a canal panam
a man a plan a canal panama
man a plan a canal panama
man a plan a canal panama
an a plan a canal panama
n a plan a canal panama
a plan a canal panama
a plan a canal panama
plan a canal panama
plan a canal panama
lan a canal panama
an a canal panama
n a canal panama
a canal panama
a canal panama
canal panama
canal panama
anal panama
nal panama
al panama
l panama
panama
panama
anama
nama
ama
ma
a
Thank you for using my program!
Due Date: 5pm, Friday, October 3
Reading: Chapter 2, Chapter 7 & Lab 4
Available Libraries: none
DNA
We can store DNA sequences as strings. These strings are made up of the letters A, C, G, and T. For a given DNA string, the GC-content is the percent of the string that is C or G, written as a decimal.
Write a program that prompts the user for a DNA string, and then prints the length and GC-content of that string.
A sample run of the program:
Enter a DNA string: ACGCCCGGGATG
Length is 12
GC-content is 0.75
Hint: See Lab 4. You can use a for-loop to go through each character in the string, and count each time you encounter a 'C' or 'G'. You can use an if-statment to check what kind of character the loop is currently on. Alternatively, you can use the count() method introduced in Lab 2 to get the total occurrences of 'C' and 'G' in the string.
Due Date: 5pm, Tuesday, October 7
Reading: Lab 4 & Numpy Tutorial
Available Libraries: matplotlib, numpy
Grayscale Image
Write a program that asks the user for a name of an image .png file and the name of an output file. The program then converts the image to grayscale and saves the grayscale image to the specified output file.
There are many ways to convert color images to grayscale (see Grayscale Algorithms for a nice overview).
For this program, we are setting each channel of a pixel to its green value. That is, your program should then set the red channel values to the green channel values, as well as the blue channel values to the green channel values. For example, a single pixel at(i,j)
of the image img
would be changed to:
img[i,j,0] = img[i,j,1] #change value of red channel to value of green channel
img[i,j,2] = img[i,j,1] #change value of blue channel to value of green channel
A sample run of your program should look like:
Enter name of the input file: csBridge.png
Enter name of the output file: gray_bridge.png
The sample input file and the resulting grayscale image:
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show()
and plt.imshow()
commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
Hint: See Lab 3. Think about how you can uses numpy slices to change every pixel.
Due Date: 5pm, Wednesday, October 8
Reading: Section 8.11, Lab 4 & Numpy Tutorial
Available Libraries: matplotlib, numpy
Topographic Map
Modify the map-making program from Lab 4 to create a topographic map (highlighting the points that have elevations that are multiples of 10) and the coastline. Your program should ask the user for the amount of intensity (a floating point number between 0.0 and 1.0), the name of the output image, and create a new image with that name and with the pixels colored as follows:
A sample run of your program should look like:
What intensity for the topo lines: 0.5
What is the output file: med_topo.png
Thank you for using my program!
Your map is stored med_gray_topo.png.
Your resulting map should look like:
and be saved to a file called med_gray_topo.png.
Another run with darker lines:
What intensity for the topo lines: 0.0
What is the output file: dark_lines_topo.png
Thank you for using my program!
Your map is stored dark_lines_topo.png.
Your resulting map should look like:
and be saved to a file called dark_lines_topo.png.
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show()
and plt.imshow()
commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
Due Date: 5pm, Thursday, October 9
Reading: Section 10.23, Chapter 4 & Lab 4
Available Libraries: none
Two-Part Numbers
Write a program that identifies all two-part numbers from a string and returns a list of those numbers. In the input string, each number is separated by a comma followed by a space: ', ', and two-part numbers contain a '-'.
For example, if you ran your program and the user entered:
Enter numbers, separated by commas: twenty, four, thirty-one, sixty-six, eight
A list of the two-part numbers: ["thirty-one", "sixty-six"]
Hint: See Section 4 in Lab 4.
Due Date: 5pm, Friday, October 10
Reading: Section 8.11, Lab 4 & Numpy Tutorial
Available Libraries: numpy, matplotlib
Logo
Write a program that creates a 'U' logo for university on a 30x30 grid. Your program should ask the user for the red, green, and blue for the color of their logo, and the file to save the image.
A sample run using Hunter College Purple (Pantone 267):
Enter amount of red: 0.373
Enter amount of green: 0.145
Enter amount of blue: 0.624
Enter file name: hunterPurple_U.png
The resulting file is:
The grading script is expecting:
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show()
and plt.imshow()
commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
Due Date: 5pm, Tuesday, October 14
Reading: Burch's Logic & Circuits & Lab 5
Available Libraries: N/A
NAND Circuit
Build a circuit that has the same behavior as a nand gate (i.e. for the same inputs, gives identical output) using only and, or, and not gates.
Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.
Due Date: 5pm, Wednesday, October 15
Reading: Burch's Logic & Circuits & Lab 5
Available Libraries: N/A
Majority Circuit
Write a logical expression that is equivalent to the circuit that computes the majority of 3 inputs, called in1, in2, in3:
Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.
Hint: See Lab 5.
Due Date: 5pm, Thursday, October 16
Reading: Chapter 7, Chapter 11, & Lab 4
Available Libraries: turtle
Turtle String
The program turtleString.py takes a string as input and uses that string to control what the turtle draws on the screen (inspired by code.org's graph paper programming). Currently, the program processes the following commands:
Modify this program to allow the user also to specify with the following symbols:
An example with the new symbols and string SrFTFFFBBBbtFLFFF would create the image:
Due Date: 5pm, Tuesday, October 21
Reading: Burch's Logic & Circuits & Lab 5
Available Libraries: N/A
Binary Number Incrementer
Logical gates can be used to do arithmetic on binary numbers. For example, we can write a logical circuit whose output is one more than the inputted number. Our inputs are in1 and in2 and the outputs are stored in out1, out2, and out3.
Here is a table of the inputs and outputs:
Inputs | Outputs | |||||
---|---|---|---|---|---|---|
Decimal Number | in1 | in2 | Decimal Number | out1 | out2 | out3 |
0 | 0 | 0 | 1 | 0 | 0 | 1 |
1 | 0 | 1 | 2 | 0 | 1 | 0 |
2 | 1 | 0 | 3 | 0 | 1 | 1 |
3 | 1 | 1 | 4 | 1 | 0 | 0 |
Submit a text file with each of the outputs on a separate line:
""" Name: YourNameHere Date: March 2025 Logical expressions for a 4-bit incrementer """ out1 = ... out2 = ... out3 = ...Where "..." is replaced by your logical expression (see Lab 5 for hints and formatting help).
Note: here's a quick review of binary numbers.
Due Date: 5pm, Wednesday, October 22
Reading: Lecture 4, Lab 4
Available Libraries: none
Fares by Time
Write a program that will ask for the time in 24 hour format (e.g. 2034 is 8:34pm) and, prints out:
A sample run:
Enter time: 1750
Peak Fare (Evening Rush)
Note: "Inclusive" for a range of numbers means that it includes the endpoints. For example, "between 4 and 8, inclusive" means all values that are greater than or equal to 4 and are also less than or equal to 8.
Due Date: 5pm, Thursday, October 23
Reading: 10-mins to Pandas, DC Pandas, Lab 6
Available Libraries: pandas
Minimal Temperatures
In Lab 6, we wrote a program that computed the average rainfall from Australian weather data. Modify the program to ask the user for the name of a CSV file and then to print out, using the data from the CSV file:
For example, running the program on rain_A.csv (a smaller version of the CSV file from the lab that's contains only the cities that start with 'A'):
Enter CSV file name: rain_A.csv
Overall min temp: -5.2
Minimum temperature by location:
Location
Adelaide 0.7
Albany 1.8
Albury -2.8
AliceSprings -5.2
Due Date: 5pm, Monday, October 27
Reading: 10-mins to Pandas, DC Pandas, Lab 6
Available Libraries: pandas
Triple Recipe
Using pandas, write a program that asks the user for a recipe (in comma separated value (CSV) format), reads in the corresponding CSV file and prints out quantities and ingredients needed to make a triple batch. Assume that the CSV files have the columns: "Amount", "Measurement", and "Ingredient".
For example if the CSV file, meringues.csv, contained:
Amount | Measurement | Ingredient |
---|---|---|
150 | grams | chocolate chips |
4 | whites of | eggs |
.25 | teaspoon | vanilla |
.25 | teaspoon | cream of tartar |