All students registered by Tuesday, January 21, 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 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
.
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:
"""
Name: Thomas Hunter
Email: thomas.hunter1870@hunter.cuny.edu
Date: February 1, 2025
This program prints: Hello, Thomas Hunter
"""
print("Hello, Thomas Hunter")
You may submit your assignments up to two 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, Monday, February 3
Reading: Chapter 1 & Lab 1
Available Libraries: Python 3.10+
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, Tuesday, February 4
Reading: Chapter 4 & Lab 1
Available Libraries: turtle, Python 3.10+
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). So, 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, February 6
Reading: Chapter 4 & Lab 1
Available Libraries: turtle, Python 3.10+
Flower
Write a program that implements the pseudocode ("informal high-level description of the operating principle of a computer program or other algorithm") below:
Repeat 50 times:
Change color to blue
Walk forward 100 steps
Turn left 155 degrees
Change color to red
Walk forward 100 steps
The result should look as follows:
Due Date: 5pm, Friday, February 7
Reading: Chapter 1 & Lab 1
Available Libraries: Python 3.10+
Multiple Greetings
Write a program that will print Hi & Bye
multiple times.
The number of times depends on your EmplID number. Take the last digit of your EmplID number and add 10. For example, if your EmplID ends in 3, the number of times you repeat the message is 3+10 = 13.
For example, with an EmplID ending in 7, you would repeat the message 17 times:
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Hi & Bye
Due Date: 5pm, Tuesday, February 11
Reading: Chapter 4 & Lab 1
Available Libraries: turtle, Python 3.10+
Green Star
Write a program that uses the turtle library to draw a green 5-pointed star.
Your output should look like this:
Hint: To draw the 5-pointed star, the turtle must turn a total of 720 degrees. How many degrees does the turtle need to turn at each point?
Due Date: 5pm, Thursday, February 13
Reading: Chapter 2 & Lab 2
Available Libraries: Python 3.10+
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 upper case letters, and the message in lower 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 upper case letters, and prints it in lower case letters. To do that, you need to store the phrase in a variable and print variations of the stored variable. See Sections 2 and 3 of Lab 2.
Due Date: 5pm, Friday, February 14
Reading: Chapter 2 & Lab 2
Available Libraries: Python 3.10+
Uppercase ASCII
Write a program that prompts the user to enter a phrase, converts the phrase to uppercase, and then prints out each uppercase character and its corresponding ASCII code.
A sample run of your program should look like:
Enter a phrase: ABC
A 65
B 66
C 67
And another sample run:
Enter a phrase: abc
A 65
B 66
C 67
Another run, with a longer phrase:
Enter a phrase: I love Python!
I 73
32
L 76
O 79
V 86
E 69
32
P 80
Y 89
T 84
H 72
O 79
N 78
! 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 73. See Lab 2.
Due Date: 5pm, Wednesday, February 19
Reading: Chapter 2 & Lab 2
Available Libraries: Python 3.10+
Counting by 25's
Write a program that prints out the numbers from 1000 to 2000, counting by twentyfives.
The output of your program should be:
1000
1025
1050
1075
1100
1125
1150
1175
1200
1225
1250
1275
1300
1325
1350
1375
1400
1425
1450
1475
1500
1525
1550
1575
1600
1625
1650
1675
1700
1725
1750
1775
1800
1825
1850
1875
1900
1925
1950
1975
2000
Due Date: 5pm, Thursday, February 20
Reading: Chapter 4 & Lab 2
Available Libraries: turtle, Python 3.10+
Twisting Square
Write a program, using the turtle library, that implements the pseudocode below:
For i = 20, 22, 24, 26, ... ,100:
Walk forward i steps
Turn right 93 degrees
Your output should look similar to:
Hint: See examples of range(start,stop,step) in Section 4 of Lab 2.
Due Date: 5pm, Friday, February 21
Reading: Chapter 2 & Lab 2
Available Libraries: Python 3.10+
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 3 of Lab 2.
Due Date: 5pm, Tuesday, February 25
Reading: Chapter 2 & Lab 2
Available Libraries: Python 3.10+
Name List
Write a program that prompts the user to enter a list of names. Each person's name is separated from the next by a semi-colon and a space ('; ') and the names are entered lastName, firstName (i.e. separated by ', '). Your program should then print out the names, one per line, with the first initial of the first name, followed by ".", and followed by the last name.
A sample run of your program should look like:
Please enter your list of names: Lovelace, Ada; Fleming, Williamina; Hopper, Grace; Easley, Annie; Wilkes, Mary Allen
A. Lovelace
W. Fleming
G. Hopper
A. Easley
M. Wilkes
Thank you for using my name organizer!
Hint: See Section 10.24 for a quick overview of split(). Do this programin parts: first, split the list by person (what should the delimiter be?). Then, split each of person's name into first and last name (what should the delimiter be here?). If you have a string str, what is s = str[0] + "."?
Due Date: 5pm, Wednesday, February 26
Reading: Chapter 4 & Lab 3
Available Libraries: turtle, Python 3.10+
Shades of Purple
Modify the program from Lab 3 to show the shades of purple.
Your output should look similar to:
Due Date: 5pm, Thursday, February 27
Reading: Chapter 2 & Lab 2
Available Libraries: Python 3.10+
String Lengths
Write a program that asks the user for a phrase, and prints out the length. 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
30
Enter phrase: That never wrote to Me-
23
Enter phrase: The simple News that Nature told-
33
Enter phrase: With tender Majesty
19
Enter phrase: Emily Dickinson
15
Due Date: 5pm, Friday, February 28
Reading: Chapter 2, Chapter 4 & Lab 3
Available Libraries: turtle, Python 3.10+
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 that color using the turtle library. 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, Tuesday, March 4
Reading: Chapter 2, Chapter 4 & Lab 3
Available Libraries: matplotlib, numpy
Blue Channel
Write a program that asks the user for a name of an image .png file and the name of an output file. Your program should create a new image that has only the blue channel of the original image.
A sample run of your program should look like:
Enter name of the input file: csBridge.png
Enter name of the output file: blueH.png
Sample input and resulting output files:
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.
Due Date: 5pm, Wednesday, March 5
Reading: Section 2.8, Chapter 4 & Lab 3
Available Libraries: turtle, Python 3.10+
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, Thursday, March 6
Reading: Section 2.7 & Lab 4
Available Libraries: Python 3.10+
Making Change
Write a program that implements the pseudocode below:
1. Ask the user for the number of cents as an integer (e.g. 99 not 0.99). 2. Print out the number of quarters (quarters = cents // 25). 3. Compute the remaining change (rem = cents % 25). 4. Print out the number of dimes (dimes = rem // 10). 5. Compute the remaining change (rem = rem % 10). 6. Print out the number of nickels (nickels = rem // 5). 7. Print out the remaining cents (cents = rem % 5).
Be sure to print how many of each coin type in the given order (quarters, followed by dimes, followed by nickels, followed by cents) each on a new line.
A sample run of your program should look like:
Enter the number of cents: 99
Quarters: 3
Dimes: 2
Nickels: 0
Cents: 4
and another sample run:
Enter the number of cents: 62
Quarters: 2
Dimes: 1
Nickels: 0
Cents: 2
Hint: See Section 2.7.
Due Date: 5pm, Friday, March 7
Reading: Chapter 2, Chapter 7 & Lab 4
Available Libraries: Python 3.10+
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: 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, Monday, March 10
Reading: Section 8.11 & Lab 4
Available Libraries: matplotlib, numpy
Topo 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, Tuesday, March 11
Reading: Section 10.23, Chapter 4 & Lab 4
Available Libraries: Python 3.10+
Names with Spaces
Write a program that identifies names that may cause issue with formatting for subsequent programs. Your program should ask the user for the last names separated by commas, and prints out a list with all the names in the list that contain spaces.
For example, if you ran your program and the user entered:
Enter names, separated by commas: Smith,Wong,St. John,Von Trapp
A list of names with spaces: ["St. John", "Von Trapp"]
Hint: See Section 4 in Lab 4.
Due Date: 5pm, Wednesday, March 12
Reading: Section 8.11 & Lab 4
Available Libraries: numpy, matplotlib, image
Logo
Write a program that creates a 'C' logo for CUNY on a 30x30 grid.
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, Thursday, March 13
Reading: Burch's Logic & Circuits& Lab 5
Available Libraries: N/A
NAND Gate
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, Friday, March 14
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.
Due Date: 5pm, Monday, March 17
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, March 18
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, March 19
Reading: Lecture 4, Numpy Tutorial
Available Libraries: numpy, image, matplotlib
Stripes
Create a program that creates a image of blue and white stripes. Your program should ask the user for the size of your image, the name of the output file, and create a .png file of stripes. For example, if the user enters 50, your program should create a 50x50 image, alternating between blue and white stripes.
Your output should look similar to this:
Enter the size: 50 Enter output file: stripes50.png
The resulting image is saved to stripes50.png:
Your output should look similar to this:
Enter the size: 25 Enter output file: stripes25.png
The resulting image is saved to stripes25.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.
Hint: See notes from Lecture 4.
Due Date: 5pm, Thursday, March 20
Reading: 10-mins to Pandas, DataCamp 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, Friday, March 21
Reading: Lab 6, Ubuntu Terminal Reference Sheet
Available Libraries: N/A
Hello (Shell Script)
Write a shell script that prints Hello, World to the screen.
Submit a single text file containing your Unix shell commands. See Lab 6 for details.
Note: for comments, shell scripts use # in front of lines (instead of the block comments surrounded by """ """) and the first line is the "shebang" line. For a proper shell script, your file should start:
#!/bin/bash #Name: YourNameHere #Email; YourEmailHere
Due Date: 5pm, Monday, March 24
Reading: GitHub Guide, Lab 6
Available Libraries: N/A
GitHub
In Lab 6, you created a GitHub account. Submit a text file with the name of your account. The grading script is expecting a file with the format:
""" Name: Your_name Email: Your_eamil Account name for my GitHub account """" AccountNameGoesHere
Note: it takes a few minutes for a newly created GitHub account to be visible. If you submit to Gradescope and get a message that the account doesn't exist, wait a few minutes and try again.
Due Date: 5pm, Tuesday, March 25
Reading: 10-mins to Pandas, DataCamp Pandas, Lab 6
Available Libraries: pandas, 3.10+
Double 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 double 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 |