General Notes


Submit the following programs via Gradescope:


    Programming Exercises


  1. Due Date: September 10 Reading: Lab 1

    Write a program that prints "Hello, World!" to the screen.

  2. Due Date: September 11 Reading: Lab 1

    Write a program that draws an Octagon using the turtle library.
    program 2

    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".

  3. Due Date: September 12 Reading: Lab 1

    Write a program that implements the pseudocode ("informal high-level description of the operating principle of a computer program or other algorithm") below:

            
              Repeat 36 times: 
                Walk forward 100 steps
                Turn left 145 degrees 
                Walk forward 10 steps 
                Turn right 90 degrees 
                Walk forward 10 steps 
                Turn left 135 degrees 
        	    Walk forward 100 steps 
             
          
    The result should look as follows:

  4. Due Date: September 13 Reading: Lab 1

    Write a program that will print "I love Python!" 25 times.

    The output of your program should be:

    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    
  5. Due Date: September 16 Reading: Lab 1

    Write a program that uses the turtle library to draw a 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?


  6. Due Date: September 17 Reading: Think CS Section 4.7

    Write a program that prints out the numbers from 2 to 17.

    The output of your program should be:

    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
  7. Due Date: September 24 Reading: Lab 2

    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, it in upper case letters, and it in lower case letters. To do that, you need to store the phrase in a variable and print variations of the stored variable.

  8. Due Date: September 26 Reading: Lab 2

    Write a program that prompts the user to enter a phrase and then prints out the ASCII code of each character in the phrase.

    A sample run of your program should look like:

    Enter a phrase:  I love Python!
    In ASCII:
    73
    32
    108
    111
    118
    101
    32
    80
    121
    116
    104
    111
    110
    33
    

    And another sample run:

    Enter a phrase: ABC
    In ASCII:
    65
    66
    67
    

    Hint: 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.

  9. Due Date: September 27 Reading: Lab 3

    Write a program that asks the user for the hexcode of a color and then displays a turtle that color.

    Make sure the turtle is the correct shape by including turtle.shape("turtle") in your program.

    A sample run of your program should look like:

    Enter a hex string:  #A922A9
    

    and the output should look similar to:

  10. Due Date: September 30 Reading: Lab 3

    Write a program that implements the pseudocode below:

        For i = 5, 10, 15, 20, 25, ... ,300:
            Walk forward i steps
            Turn left 91 degrees
    
    Your output should look similar to:

    Hint: See examples of range(start,stop,step) in Lab 2.


  11. Due Date: October 1 Reading: Lab 3

    Modify the program from Lab 3 to show the shades of blue.

    Your output should look similar to:

  12. Due Date: October 7 Reading: Lab 3

    Draw a cornflower blue pentagon using the turtle library. You can specify the color by name ("cornflowerblue"), by hex string ("#6495ED"), or by 255-mode values (100, 149, 237). The turtle should be turtle shaped. Your turtle should move forward 100 units, turn left the correct amount of degrees, and then stamp.

    A sample run of your program will look like:

    Hint: See Lab 3.

  13. Due Date: October 8 Reading: Lab 2

    Write a program that asks the user for a message, then prints out that message in reverse. The reversed output message should be printed with two copies of each character per line.

    A sample run of your program should look like:

    Enter a message: I love Python!
    ! !
    n n
    o o
    h h
    t t
    y y
    P P
    
    e e
    v v
    o o
    l l
    
    I I
    

    Hint: use a for-loop that starts at the last index in the string and stops at the first index in the string:

    lastIdx = len(myString) - 1
    for i in range(lastIdx, -1, -1):
      #print each character in myString, twice on each line
    

  14. Due Date: October 9 Reading: Lab 4

    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:

  15. Due Date: October 15 Reading


    (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 a word: zebra
    Your word in code is:
    mroen
    

    Hint: You can use this file to get started with this assignment.

  16. Due Date: October 16 Reading: Lab 4

    Write a program that converts kilometers to miles. Your program should prompt the user for the number of kilometers and then print out the number of miles.

    A useful formula: miles = 0.621371*kilometers.

  17. Due Date: October 22 Reading: Lab 4

    Write a program that implements the pseudocode below:

    1.  Ask the user for the number of hours until the weekend.
    2.  Print out the days until the weekend (days = hours // 24)
    3.  Print out the leftover hours (leftover = hours % 24)
    

    A sample run of your program should look like:

    Enter number of hours:  27
    Days: 1
    Hours: 3
    

    and another sample run:

    Enter number of hours:  52
    Days: 2
    Hours: 4
    

    Hint: See Section 2.7.

  18. Due Date: October 23 Reading: Lab 5

    Following Lab 5, write a program that asks the user for the name of a png file and print the number of pixels that are nearly white (the fraction of red, the fraction of green, and the fraction of blue are all above 0.75).

    For example, if your file was of the snow pack in the Sierra Nevada mountains in California in September 2014:

    then a sample run would be:

    Enter file name:  caDrought2014.png
    Snow count is 38010

    Note: for this program, you only need to compute the snow count. Showing the image will confuse the grading script, since it's only expecting the snow count.

  19. Due Date: October 28 Reading: Lab 2 and Lab 4

    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.


  20. Due Date: October 29 Burch's Logic & Circuits
    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.

  21. Due Date: October 30 Burch's Logic & Circuits

    Build a circuit that has the same behavior as a nor 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.

  22. Due Date: October 31 Burch's Logic & Circuits

    Write a logical expression that is equivalent to the circuit that computes the majority of 3 inputs, called in1, in2, in3:

    • If two or more of the inputs are True, then your expression should evaluate to True.
    • Otherwise (two or more of the inputs are False), then your expression should evaluate to False.

    Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.

  23. Due Date: November 1 Reading: Lab 5

    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:
    InputsOutputs
    Decimal
    Number
    in1in2Decimal
    Number
    out1out2out3
    000 1001
    101 2010
    210 3011
    311 4100

    Submit a text file with each of the outputs on a separate line:

    #Name:  YourNameHere
    #Date:  October 2024
    #Logical expressions for a 4-bit incrementer
    
    out1 = ...
    out2 = ...
    out3 = ...
    
    Where "..." is replaced by your logical expression (see Lab 5).

    Note: here's a quick review of binary numbers.

  24. Due Date: November 4 Think CS: Chapter 4 & Section 7.4

    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:

    • 'F': moves the turtle forward 50 steps
    • 'L': turns the turtle 90 degrees to the left
    • 'R': turns the turtle 90 degrees to the right
    • '^': lifts the pen
    • 'v': lowers the pen
    For example, if the user enters the string "FLFLFLFL^FFFvFLFLFLFL", the turtle would move forward and then turn left. It repeats this 4 times, drawing a square. Next, it lifts the pen and move forward 3, puts the pen back down and draw another square.

    Modify this program to allow the user also to specify with the following symbols:

    • 'B': moves the turtle backwards 50 steps
    • 'S': makes the turtle stamp
    • 'l': turns the turle 45 degrees to the left
    • 'r': turns the turtle 45 degrees to the right
    • 'p': change the pen color to purple
  25. Due Date: November 5 GitHub Guide

    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
    #Date:  October 2024
    #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.

  26. Due Date: November 14 Lab 3

    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 (that is, no 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:  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.

  27. Due Date: December 18 Reading:

    Write a program that implements the pseudocode below:

    For i = 90, 88, 86, 84, 82, ... ,0:
    	Walk forward 25 steps
    	Turn left i degrees
    

    Your output should look similar to:


  28. Due Date: December 18 Reading:

    Write a program that creates a 'C' logo for CUNY on a 30x30 grid.

    The grading script is expecting:

    • The file to be saved as: logo.png.
    • The grid to be 30 x 30.
    • The 'C' to be 0% red, 0% green, and 100% blue. The upper part of the 'C' should be the top third of the image; the left part of the 'C' should be the left third of the image; and the lower part of the 'C' should be the the bottom third of the image.
    • The remaining pixels in the image should be white (100% red, 100% green, and 100% blue).

    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.

  29. Due Date: December 18 Reading:

    Modify the flood map of NYC from Lab 4 to color the region of the map with elevation greater than 6 feet and less than or equal 20 feet above sea level the color grey (50% red, 50% green, and 50% blue).

    Your resulting map should look like:

    and be saved to a file called floodMap.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.show() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.

  30. Due Date: December 18 Reading:

    Write a program that computes the minimum, average, and maximum population over time for a borough (entered by the user). Your program should assume that the NYC historical population data file, nycHistPop.csv is in the same directory.

    A sample run of your program:

    Enter borough: Staten Island
    Minimum population:  727
    Average population:  139814.23076923078
    Maximum population:  474558
    

    and another run:

    Enter borough: Brooklyn
    Minimum population:  2017
    Average population:  1252437.5384615385
    Maximum population:  2738175
    

    Hint: See Lab 6.

  31. Due Date: December 18 Reading:

    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:  Cohn, Mildred; Dolciani, Mary P.; Rees, Mina; Teitelbaum, Ruth; Yalow, Rosalyn
    
    You entered:
    
    M. Cohn
    M. Dolciani
    M. Rees
    R. Teitelbaum
    R. Yalow
    
    Thank you for using my name organizer!
    

    Hint: Do this problem in 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] + "."?

  32. Due Date: December 18 Reading:

    Modify the map-mapking program from Lab 4 to create a topographic map (highlighting the points that have elevations that are multiples of 10). Your program should ask the user for the amount of blue (a floating point number between 0.0 and 1.0), the name of the output imagee, create a new image with thaht name and with the pixels colored as follows:

    • If the elevation is less than or equal to 0, color the pixel the amount blue the user specified (and 0% red and 0% green).
    • If the elevation is divisible by 10, color the pixel black (0% red, 0% green, and 0% blue).
    • Otherwise, the pixel should be colored white (100% red, 100% green, and 100% blue).

    A sample run of your program should look like:

    How blue is the ocean:  0.5
    What is the output file:  medBlue.png
    Thank you for using my program!
    Your map is stored medBlue.png.

    Your resulting map should look like:

    and be saved to a file called medBlue.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.

  33. Due Date: December 18 Reading:

    Modify the program from Lab 6 that displays the NYC historical population data. Your program should ask the user for the borough, an name for the output file, and then display the fraction of the population that has lived in that borough, over time.

    A sample run of the program:

    Enter borough name:  Queens
    Enter output file name:  qFraction.png
    

    The file qFraction.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.

  34. Due Date: December 18 Reading:

    Write a program that implements the pseudocode below:

    1.  Ask the user for the number of seconds until lecture starts.
    2.  Print out the hours until lecture (hours = seconds //3600).
    3.  Compute the remaining seconds (rem = seconds % 3600).
    4.  Print out the minutes until lecture (minutes = rem // 60).
    5.  Print out the remaining seconds (remSec = rem % 60).
    

    A sample run of your program should look like:

    Enter number of seconds:  62
    Hours: 0
    Minutes: 1
    Seconds: 2
    

    and another sample run:

    Enter number of seconds:  4000
    Hours: 1
    Minutes: 6
    Seconds: 40
    

  35. Due Date: December 18 Reading:

    Write a Bash script that prints Hello, World to the screen.

    Submit a single text file containing your Unix shell commands. See Lab 6 for details.

  36. Due Date: December 18 Reading: