General Notes


Submit the following programs via Gradescope:


  1. Due Date: 6 September Reading: Think CS: Chapters 1 & 2

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

    Hint: See the introductory lab.

  2. Due Date: 9 September Reading: Think CS: Chapter 4

    Write a program that draws an octagon (8-sided polygon).

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

    Hint: See the introductory lab.

  3. Due Date: 10 September Reading: Think CS: Chapter 4

    Copy the program from Section 4.3 into a file on your computer and modify the program (with turtles alex and tess) to have a blue background color and have tess draw red lines:

  4. Due Date: 11 September Reading: Think CS: Chapter 2 and Section 4.7

    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 55 degrees
            Walk forward 10 steps
            Turn left 55 degrees
            Walk forward 100 steps
    
    Your output should look similar to:
  5. Due Date: 12 September Reading: Think CS: Chapter 4

    Write a program that will prints your name 25 times.

    For example, the output of Thomas Hunter's program should be:

    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    Thomas Hunter
    

    Note: the grading scripts expect the name associated with your Gradescope account (down to spaces and punctuation). If you get an error that the names do not match, compare carefully the name you printed and the name on file. If your name is not correct on Gradescope, send email to hunterCSci127help AT gmail.com with the correct name.

  6. Due Date: 13 September Reading: Think CS: Chapter 2 and and Section 4.7

    Write a program that prints out the numbers from 0 to 24.

    The output of your program should be:

    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    

    Hint: Use a loop and print out the index or loop variable.

  7. Due Date: 16 September Reading: Think CS: Chapters 2 & 9

    Using the string commands introduced in Lab 1, 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: 17 September Reading: Think CS: Chapters 2 & 9

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

  9. Due Date: 18 September Reading: Think CS: Chapters 2 & 9


    (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: See the example programs from Lecture 2.

  10. Due Date: 19 September Reading: Think CS: Chapters 2 & 4

    Write a program that prompts the user for a DNA string, and then prints the length and GC-content (percent of the string that is C or G, written as a decimal).

    A sample run of your program should look like:

    Enter a DNA string:  ACGCCCGGGATG
    Length is 12
    GC-content is 0.75
    

    And another sample run:

    Enter a DNA string:  AAAAA
    Length is 5
    GC-content is 0.0
    

    Hint: See Lab 1.

  11. Due Date: 20 September Reading: Think CS: Sections 2.7 & 9.5

    Write a program that asks the user for a noun and two verbs (inspired by a Colgate University COSC 101 program). Using the words the user entered, print out a new sentence of the form:

    	If it VERB1 like a NOUN and VERB2 like a NOUN, it probably is a NOUN.
    	
    A sample run of the program:
    Enter a noun: duck
    Enter a verb: walks
    Enter another verb: talks
    
    New sentence:
    If it walks like a duck and talks like a duck, it probably is a duck.
    
    Another sample run of the program:
    Enter a noun: cat
    Enter a verb: sounds
    Enter another verb: moves
    
    New sentence:
    If it sounds like a cat and moves like a cat, it probably is a cat.
    

    Hint: Here's a way to approach the problem:

    1. Create a variable, template and store the string "If it VERB1 like a NOUN and VERB2 like a NOUN, it probably is a NOUN." in it.
    2. Ask the user for a noun and store it in a variable, noun.
    3. Replace the placeholder in the template with the noun the user entered (i.e. template = template.replace("NOUN", noun)).
    4. Ask the user for a verb and store it in a variable, verb1.
    5. Replace the placeholder in the template with the verb the user entered.
    6. Ask the user for another verb and store it in a variable, verb2.
    7. Replace the placeholder in the template with the second the verb the user entered.
    8. Print out the updated template string.
  12. Due Date: 23 September Reading: Think CS: Chapter 2

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

    Your output should look similar to:

  13. Due Date: 24 September Reading: Think CS: Section 8.10 & Datacamp Numpy Tutorial

    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.

    Hint: See Lab 2.

  14. Due Date: 25 September Reading: Think CS: Chapter 2 & Section 8.2

    In Lecture 3, we wrote a program to make a Hunter logo 'H' on a 10x10 grid. 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.

    Hint: See notes from Lecture 3.

  15. Due Date: 26 September Reading: Think CS: Chapters 2 & 8.10 & Datacamp Numpy Tutorial

    Modify the flood map of NYC from Lab 3 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.

  16. Due Date: 27 September Reading: Think CS: Chapter 2

    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.

    See Lab 3 for designing Input-Process-Output programs.

  17. Due Date: 2 October Reading: Think CS: Section 2.7

    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
    

    Hint: See Section 2.7.

  18. Due Date: 3 October Reading: Think CS: Chapter 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:

  19. Due Date: 4 October Reading: Think CS: Chapters 2 & 9

    Write a program that asks the user for a message and then prints the message out, three copies of one character per line.

    A sample run of your program should look like:

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

    And another sample run:

    Enter a message: Hunter
    H H H
    u u u
    n n n
    t t t
    e e e
    r r r
    

    Note: The print() command can take multiple inputs to print at the same time. For example, print(c,c) will print the contents of variable c twice. For example, if c is "I", then it would print: I I.

    Hint: See Lab 1 or Lecture 2 notes.

  20. Due Date: 7 October Reading: Section 10.24

    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: See Section 10.24 for a quick overview of split(). 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] + "."?

  21. Due Date: 10 October Reading: Think CS: Chapters 2 & 9

    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:

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

  22. Due Date: 11 October Reading: Think CS: Chapters 7 & 8.10 & Datacamp Numpy Tutorial

    Following Lab 4, 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.

  23. Due Date: 15 October Reading: 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 4 for the format for submitting logical expressions to Gradescope.

  24. Due Date: 16 October Reading: Think CS: Chapters 7 & 8.10 & Datacamp Numpy Tutorial

    Modify the map-mapking program from Lab 3 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.

  25. Due Date: 17 October Reading: 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 4 for the format for submitting logical expressions to Gradescope.

  26. Due Date: 18 October Reading: 10-mins to Pandas, DataCamp Pandas

    Modify the program from Lab 5 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.

  27. Due Date: 21 October Reading: 10-mins to Pandas, DataCamp Pandas

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

  28. Due Date: 22 October Reading: Ubuntu Terminal Reference Sheet

    Write an Unix shell script that prints Hello, World to the screen.

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

  29. Due Date: 23 October Reading: Github Guide

    In Lab 5, 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:  November 2017
    #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.

  30. Due Date: 24 October Reading: Think CS: Chapter 7

    The program, turtleString.py (available at: https://github.com/stjohn/csci127) 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
    • 'B': moves the turtle backwards 50 steps
    • 'g': change turle color to green
    • 'b': change turle color toblue
    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:

    • '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 turtle color to purple

    Hint: See Lecture 4 notes.

  31. Due Date: 25 October Reading: 10-mins to Pandas, DataCamp Pandas

    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:

    AmountMeasurementIngredient
    150gramschocolate chips
    4whites ofeggs
    .25teaspoonvanilla
    .25teaspooncream of tartar

    A sample run of your program would be:

    Enter recipe name: meringues.csv
    Double your recipe is:
           Amount Measurement       Ingredient
        0   300.0       grams  chocolate chips
        1     8.0   whites of             eggs
        2     0.5    teaspoon          vanilla
        3     0.5    teaspoon  cream of tartar
    
  32. Due Date: 28 October Reading: 10-mins to Pandas, DataCamp Pandas

    Modify the program from Lab 6 that displays shelter population over time to:

    • ask the user to specify the input file,
    • ask the user to specify the output file,
    • make a plot of the fraction of the total population that are children over time from the data in input file, and
    • store the plot in the output file the user specified.

    A sample run of the program:

    Enter name of input file:  DHS_2015_2016.csv
    Enter name of output file:  dhsPlot.png
    

    which produces an output:

    Note: The grading script is expecting that the label (i.e. name of your new column) is "Fraction Children".

  33. Due Date: 29 October Reading: Think CS Section 6.7

    Write a program, using a function main() that prints "Hello, World!" to the screen. See Lab 6.

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

    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.


    (click to launch new window with circuit)

    Here is a table of the inputs and outputs:

  35. 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:  November 2017
    #Logical expressions for a 4-bit incrementer
    
    out1 = ...
    out2 = ...
    out3 = ...
    
    Where "..." is replaced by your logical expression (see Lab 4).

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

  36. Due Date: 1 November Reading: 10-mins to Pandas, DataCamp Pandas

    Modify the parking ticket program from Lab 7 to do the following:

    • Ask the user for the name of the input file.
    • Ask the user for the attribute (column header) to search by.

    A sample run:

    Enter file name:  Parking_Violations_Jan_2016.csv
    Enter attribute:  Vehicle Color
    The 10 worst offenders are:
    WHITE    2801
    WH       2695
    GY       1420
    BK       1153
    BLACK    1054
    BROWN     727
    BL        656
    GREY      574
    SILVE     450
    BLUE      412
    Name: Vehicle Color, dtype: int64
    

    And another run:

    Enter file name:  Parking_Violations_Jan_2016.csv
    Enter attribute:  Vehicle Year
    The 10 worst offenders are:
    0       3927
    2015    1265
    2014    1143
    2013    1105
    2012     772
    2011     666
    2007     643
    2008     559
    2010     509
    2006     499
    Name: Vehicle Year, dtype: int64
    
  37. Due Date: 4 November Reading: 10-mins to Pandas, DataCamp Pandas

    Write a program that asks the user for a CSV of the NYC OpenData Film Permits:

    • There is a sample file for June 2019 film permits on github.
    Your program should then print out:
    • the total number of permits in the file,
    • the count of permits for each borough, and
    • the five most popular locations (stored in the column: "Parking Held").

    A sample run:

    Enter file name: filmPermitsJune2019.csv
    
    There were 643 film permits.
    Manhattan        336
    Brooklyn         165
    Queens            70
    Staten Island     42
    Bronx             30
    Name: Borough, dtype: int64
    
    The five most popular filming locations were:
    WEST   48 STREET between 6 AVENUE and 7 AVENUE                                                                                                                                       25
    EAST  140 STREET between LOCUST AVENUE and WALNUT AVENUE,  WALNUT AVENUE between EAST  139 STREET and EAST  140 STREET,  EAST  139 STREET between WALNUT AVENUE and LOCUST AVENUE    15
    FROST STREET between DEBEVOISE AVENUE and MORGAN AVENUE,  DEBEVOISE AVENUE between FROST STREET and RICHARDSON STREET                                                                11
    ASHLAND PLACE between LAFAYETTE AVENUE and HANSON PLACE                                                                                                                              10
    EAST   11 STREET between 3 AVENUE and 4 AVENUE,  3 AVENUE between EAST   11 STREET and EAST   12 STREET                                                                               9
    Name: ParkingHeld, dtype: int64
    

    This assignment uses film permit data collected and made publicly by New York City Open Data, and can be found at:

    https://data.cityofnewyork.us/City-Government/Film-Permits/tg4x-b46p.
    Since the files are quite large, use the "Filter" option and a range of dates for "StartDateTime" and "Export" (in CSV format) all permits for those dates.

    Hint: See Lab 7 for accessing and analyzing structured data.

  38. Due Date: 5 November Reading: Think CS Chapter 7 and Section 9.10

    Write a program that implements the pseudcode below. Your program should ask the user for a binary number and print out the corresponding decimal number.

        Ask user for input, and store in the string, binString.
        Set decNum = 0.
        For each c in binString,
            decNum = decNum * 2
            if c is 1, then
                decNum = decNum + 1
        Print decNum
    		

    A sample run of the program:

    Enter binary number: 10
    Your number in decimal is 2
    

    And another sample run of the program:

    Enter binary number: 1111
    Your number in decimal is 15
    
  39. Due Date: 6 November Reading: Think CS Chapter 6

    Fill in the missing function, num2string(), in the program, numsConvert.py (available at: https://github.com/stjohn/csci127). The function should take number between 0 and 9 as a parameter and returns the corresponding number as a string. For example, if the parameter is 0, your function should return "zero". If the parameter is 1, your function should return out "one", etc.

    Note: The grading scripts are expecting that your function is called num2string(). You need to use that name, since instead of running the entire program, the scripts are "unit testing" the function-- that is, calling that function, in isolation, with differrent inputs to verify that it performs correctly.

    Hint: See notes from Lecture 7 and Lab 7.

  40. Due Date: 7 November Reading: Think CS Chapter 6 and Chapters 7

    Write a function, computeFare(), that takes as two parameters: the zone and the ticket type, and returns the Copenhagen Transit fare.

    • If the zone is 2 or smaller and the ticket type is "adult", the fare is 23.
    • If the zone is 2 or smaller and the ticket type is "child", the fare is 11.5.
    • If the zone is 3 and the ticket type is "adult", the fare is 34.5.
    • If the zone is 3 or 4 and the ticket type is "child", the fare is 23.
    • If the zone is 4 and the ticket type is "adult", the fare is 46.
    • If the zone is greater than 4, return a negative number (since your calculator does not handle inputs that high).

    A template program, copenhagenTransit.py, is available on the CSci 127 repo on github. The grading script does not run the whole program, but instead tests your function separately ('unit tests') to determine correctness. As such, the name of the function must match exactly (else, the scripts cannot find it).

    A sample run:

    Enter the number of zones: 3
    Enter the ticket type (adult/child): Adult
    The fare is 34.5
    

    And another:

    Enter the number of zones: 2
    Enter the ticket type (adult/child): child
    The fare is 11.5
    

    Hint: See Lab 7.

  41. Due Date: 8 November Reading: 10-mins to Pandas, DataCamp Pandas

    In Lab 6, we worked through a program that displayed the homeless shelter occupancy over time. The same approach can be used for displaying any dataset where the date and time are stored. For this program, use the lab as a starting point to display public school attendance from NYC OpenData. If you would like to test your program on other data, you can filter for an individual school by viewing the data and filtering on the school number ("School DBN"). Export the file as CSV and save. There is a sample file for the high school on campus on github

    Modify the program from Lab 6 that displays shelter population over time to:

    • Ask the user to specify the input file,
    • Ask the user to specify the output file,
    • Convert the date column (which is stored as 'YYYYMMDD') to a datetime format recognized by pandas, for example if your dataframe is df, overwrite the 'Date' column to be:
      df["Date"] = pd.to_datetime(df["Date"].apply(str))	
    • Make a plot of the percentage of those who attended over time from the data in input file, and
    • Store the plot in the output file the user specified.

    A sample run of the program:

    Enter name of input file:  dailyAttendanceManHunt2019.csv
    Enter name of output file:  manHunt.png
    

    which produces an output:

    Note: The grading script is expecting that the label (i.e. name of your new column) is "% Attending" and the range of values be between a percentage between 0 and 100 (hint: would do you multiply by to convert a fraction into a percentage?).

  42. Due Date: 11 November Reading: Think CS: Chapter 6

    Write two functions, triangle() and nestedTriangle(). Both functions take two parameters: a turtle and an edge length. The pseudocode for triangle() is:

        triangle(t, length):
        1.  If length > 10:
        2.     Repeat 3 times:
        3.         Move t, the turtle, forward length steps.
        4.         Turn t left 120 degrees.
        5.     Call triangle with t and length/2.
    

    The pseudocode for nestedTriangle() is very similar:

        nestedTriangle(t, length):
        1.  If length > 10:
        2.     Repeat 3 times:
        3.         Move t, the turtle, forward length steps.
        4.         Turn t left 120 degrees.
        5.         Call nestedTriangle with t and length/2.
    

    A template program, nestingTrianges.py, is available on the CSci 127 repo on github. The grading script does not run the whole program, but instead tests your function separately ('unit tests') to determine correctness. As such, the function names must match exactly (else, the scripts cannot find it). Make sure to use the function names from the github program (it is expecting triangle() and nestedTriangle()).

    A sample run:

    Enter edge length:  160
    

    which would produce:

  43. Due Date: 12 November Reading: Think CS: Chapter 6 and Section 8.10

    Fill in the missing functions:

    • average(region): Takes a region of an image and returns the average red, green, and blue values across the region.
    • setRegion(region,r,g,b): Takes a region of an image and red, green, and blue values, r, g, b. Sets the region so that all points have red values of r, green values of g, and blue values of b.

    The functions are part of a program that averages smaller and smaller regions of an image until the underlying scene is visible (inspired by the elegant koalas to the max).

    For example, if you inputted our favorite image, you would see (left to right):

    and finally:

    A template program, averageImage.py, is available on the CSci 127 repo on github. The grading script does not run the whole program, but instead runs each of your functions separately ('unit tests') to determine correctness. As such, the names of the functions must match exactly the ones listed above (else, the scripts cannot find them).

    Hint: See notes from Lecture 8.

  44. Due Date: 13 November Reading: Think CS: Chapters 4 and 6

    Fill in the missing function to animate hurricane data (inspired by the 2018 Nifty Hurricane Program by Phil Ventura). Your function, animate(t,lat,lon,wind) takes as input:

    • t: a turtle,
    • lat: an integer storing the current latitude,
    • lon: an integer storing the current longitude, and
    • wind: the current wind speed in miles per hour.

    Your function should move to the turtle to the current location (longitude, latitude), and then based on the Saffir-Simpson Hurricane Wind Scale, change the turtle to be:

    • red and pen size 5 for Category 5 (windspeed > 157 mph)
    • orange and pen size 4 for Category 4 (windspeed in 130-156 mph)
    • yellow and pen size 3 for Category 3 (windspeed in 111-129 mph)
    • green and pen size 2 for Category 2 (windspeed in 96-110 mph)
    • blue and pen size 1 for Category 1 (windspeed in 74-95 mph)
    • white and pen size 1 if not hurricane strength

    A template program, hurricane.py, and background image, mapNASA.gif, are available on the CSci 127 repo on github. The grading script does not run the whole program, but instead runs each of your functions separately ('unit tests') to determine correctness. As such, the names of the functions must match exactly the ones listed above (else, the scripts cannot find them).

    Two test files (irma.csv and jose.csv) are from the Nifty site. Additional CSV files are available there.

    Hint: You may find the following turtle commands useful: color(), goto(), and pensize().

  45. Due Date: 14 November Reading: Folium Tutorial

    Write a program that uses folium to make a map of New York City. Your map should be centered at (40.75, -74.125) and include a marker for the main campus of Hunter College. The HTML file your program creates should be called: nycMap.html

    Hint: See Lab 8.

  46. Due Date: 15 November Reading: Folium Tutorial

    Using folium (see Lab 8), write a program that asks the user for the name of a CSV file, name of the output file, and creates a map with markers for all the traffic collisions from the input file.

    A sample run:

    Enter CSV file name:  collisionsThHunterBday.csv
    Enter output file:  thMap.html
    

    which would produce the html file:

    (The demo above is for October 18, 2016 using the time the collision occurred ("TIME") to label each marker and changed the underlying map with the option: tiles="Cartodb Positron" when creating the map.)

    This assignment uses collision data collected and made publicly by New York City Open Data. A sample file, collisionsThHunterBday.csv from 18 October 2016 was downloaded and can be used to test your program.

    Note: when creating datasets to test your program, you will need to filter for both date (to keep the files from being huge) and that there's a location entered. The former is explained above; to check the latter, add the additional filter condition of "LONGITUDE is not blank".

    Hint: For this data set, the names of the columns are "LATITUDE" and "LONGITUDE" (unlike the previous map problem, where the data was stored with "Latitude" and "Longitude").

  47. Due Date: 18 November Reading: Think CS: Chapters 3 & 6

    The program, errorsHex.py, has lots of errors. Fix the errors and submit the modified program.

    Hint: See Lab 8.

  48. Due Date: 19 November Reading: Chapter 8

    Modify the program from Lab 9 that makes a turtle walk 100 times. Each "walk" is 30 steps forward and the turtle can turn left 0,10,20,...,350 degrees (chosen randomly) at the beginning of each walk.

    A sample run of your program:

  49. Due Date: 20 November Reading: Chapter 8

    Write a program that asks the user to enter their age. If the user enters negative number, your program should continue prompting the user for a positive number until they enter a one. Your program should then print out the number entered.

    A sample run of your program:

    Enter your age: -100
    You entered a negative number.  Try again.
    Enter your age: -17
    You entered a negative number.  Try again.
    Enter your age: 19
    You entered: 19
    

    Hint: See Lab 9.

  50. Due Date: 21 November Reading: Ubuntu Terminal Reference Sheet

    Write an Unix shell script that does the following:

    • Creates a directory, projectFiles.
    • Creates 3 additional directories (as subdirectories of projectFiles): source, data, and results.
    Submit a single text file containing your shell commands. See Lab 10.

    Hint: See Lab 10.

  51. Due Date: 22 November Reading: MIPS Wikibooks

    Write a simplified machine language program that prints: Hello, World!

    See Lab 10 for details on submitting the simplified machine language programs.

    Hint: You may find the following table useful:


    (Image from wikimedia commons)

    Hint: The grading scripts are matching the phrase exactly, so, you need to include the spacing and punctuation.

  52. Due Date: 25 November Reading: MIPS Wikibooks

    Write a simplified machine language program that has register $s0 loop through the numbers 2, 4, 6, 8, ..., 20.

    See Lab 10 for details on submitting the simplified machine language programs.

  53. Due Date: 26 November Reading: Ubuntu Terminal Reference Sheet

    Using Unix shell commands, write a script that counts the number of .py files in current working directory.

    Hint: See Lab 10.

  54. Due Date: 2 December Reading: Cplusplus Tutorial

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

    Hint: See Lab 11 for getting started with C++.

  55. Due Date: 3 December Reading: Cplusplus Tutorial

    Write a C++ program that will print "I love C++" 14 times.

    The output of your program should be:

    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    I love C++
    

    Hint: See Lab 11 for getting started with C++.

  56. Due Date: 4 December Reading: Cplusplus Tutorial

    Write a C++ program that converts farenheit to celsius. Your program should prompt the user for the degrees in farenheit and then print out the temperature in celsius.

    A useful formula: celsius = (farenheit - 32.0) * (5.0/9.0).

    Please include the decimal digit in your formula (.0) and output with cout << fixed << ... to enforce output with decimal places even when 0

    See Lab 3 for designing Input-Process-Output programs and Lab 11 for getting started with C++.

  57. Due Date: 5 December Reading: Cplusplus Tutorial

    Write a C++ program program that asks the user for two numbers x and y, and draws a grid of zeros and ones with x rows and y columns using 'character graphics'.

    A sample run:

    Enter the number of rows:  3
    Enter the number of columns:  6
    101010
    010101
    101010
    

    Another sample run:

    Enter the number of rows:  3
    Enter the number of columns:  3
    101
    010
    101
    

    Hint: if your nested loops have index variables, i and j, then what does: cout << ((i+j+1)%2) do?

  58. Due Date: 6 December Reading: Cplusplus Tutorial

    Write a C++ program that asks the user for their average grade and prints

    • "Your letter grade is F" if it is strictly less than 60,
    • "Your letter grade is C or D" if it is 60 or greater, but strictly less than 80,
    • "Your letter grade is B" if it is 80 or greater, but strictly less than 90, and
    • "Your letter grade is A" otherwise.

    A sample run:

    Enter your average grade:  93.6
    Your letter grade is A
    

    Another sample run:

    Enter your average grade:  79.8
    Your letter grade is C or D
    

    And another run:

    Enter your average grade:  80.8
    Your letter grade is B
    
  59. Due Date: 9 December Reading: Cplusplus Tutorial

    Write a C++ program that asks the user for their weekly salary, and continue asking until the number entered is positive (that is, greater than 0).

    A sample run:

    Please enter your salary: -900
    Entered a negative number.
    Please enter your salary: -90.0
    Entered a negative number.
    Please enter your salary: 900
    Your weekly salary is $900
    

    Hint: The logic here is similar to the Python program from Lab 9 in C++.

  60. Due Date: 10 December Reading: Cplusplus Tutorial

    Write a C++ program that asks the user for an initial dollar amount. It then repeatedly asks for the amount spent and reports on the remaining amount, until it runs out of money.

    A sample run:

    Please enter the initial dollar amount:100
    Please enter the amount you spent:13.5
    You now have $86.5 remaining
    Please enter the amount you spent:34
    You now have $52.5 remaining
    Please enter the amount you spent:26.9
    You now have $25.6 remaining
    Please enter the amount you spent:500
    You now have $-474.4 remaining
    Your initial amount has been entirely spent
    

    Hint: Use an indefinite loop and continue looping while the amount is is greater than 0.

  61. Due Date: 11 December Reading: Cplusplus Tutorial

    Write a C++ program that asks the user for a whole number between -31 and 31 and prints out the number in "two's complement" notation, using the following algorithm:

    1. Ask the user for a number, n.
    2. If the number is negative, print a 1 and let x = 32 + n.
    3. If the number is not negative, print a 0 and let x = n.
    4. Let b = 16.
    5. While b > 0.5:
      1. If x >= b then print 1, otherwise print 0
      2. Let x be the remainder of dividing x by b.
      3. Let b be b/2.
    6. Print a new line ('\n').

    A sample run:

    Enter a number:  8
    001000
    

    Another run:

    Enter a number: -1
    111111
    
Here's xkcd on the simplicity of Python:

(This file was last modified on 6 November 2019.)