There is a dedicated computer laboratory for this course at HUNTER NORTH 1001E. It is the same lab where you have your recitation sessions! It is staffed with tutors, who are there to help you. Please take advantage of it.
MONDAYS and WEDNESDAYS from 9:30am to 6:00pm
TUESDAYS and THURSDAYS from 3:00PM to 6:00PM
#Name: Thomas Hunter
#Date: May 30, 2018
#This program prints: Hello, World!
print("Hello, World!")
Submit the following programs via Gradescope:
01) Due Date: 6 June Reading: Think CS Chapters 1 & 2
Write a program that prints "Hello, World!" to the screen.
_Hint: See [Lab 1](lab_01.html){:target="_blank"}._
02) Due Date: 6 June Reading: Think CS Chapters 2 & 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 [Lab 1](lab_01.html){:target="_blank"}._
03) Due Date: 6 June Reading: Think CS Chapters 2 & 4
Write a program that implements the [pseudocode](http://en.wikipedia.org/wiki/Pseudocode) ("informal high-level description of the operating principle of a computer program or other algorithm") below:
Repeat 45 times:
Walk forward 100 steps
Turn right 92 degrees
Walk forward 10 steps
Turn right 92 degrees
Your output should look similar to:
![](/127/flower.png)
04) Due Date: 6 June Reading: Think CS Chapters 2 & 4
Write a program that will print the Hunter College motto ("Mihi cura futuri" which translates to: "The care of the future is mine") 19 times.
The output of your program should be:
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
Mihi cura futuri
05) Due Date: 6 June Reading: Think CS Chapters 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 purple background color and have tess draw white lines:
06) Due Date: 6 June Reading: Think CS Chapters 2 & Section 4.7
Write a program that prints out the numbers from 0 to 14.
The output of your program should be:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
_Hint: Use a loop and print out the index or loop variable._
07) Due Date: 11 June Reading: Think CS Chapters 2 & 4
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!
08) Due Date: 11 June 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
_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](lab_02.html){:target="_blank"}._
09) Due Date: 11 June Reading: Think CS Chapters 2 & 9
![](https://stjohn.github.io/teaching/csci127/f18/ciphrdsk.gif)
(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: 11 June Reading: Think CS Chapters 2 & 9
Write a program that implements the pseudocode below:
For i = 10, 20, 30, ..., 100:
Walk forward i steps
Turn left 94 degrees
Your output should look similar to:
![](/127/spiral10.png)
_Hint: See [Lab 2](lab_02.html){:target="_blank"}._
11) Due Date: 13 June Reading: Think CS Chapters 4 & 9
Write a program that asks the user for a message and then prints the message out, one character per line, in reverse order.
A sample run of your program should look like:
Enter a message: I love Python!
!
n
o
h
t
y
P
e
v
o
l
I
_Hint: See [Lab 2](lab_02.html) or Lecture 2 notes._
12) Due Date: 13 June Reading: Think CS Chapters 2 & 4
Modify the program from [Lab 3](lab_03.html){:target="_blank"} to show the shades of green.
Your output should look similar to:
![](/127/shadesOfGreen.png)
13) Due Date: 13 June Reading: Think CS Chapters 2 & 4
Write a program that asks the user for the hexcode of a color and then displays a turtle that color.
A sample run of your program should look like:
Enter a hex string: #A922A9
and the output should look similar to:
![](/127/purpleTurtle.png)
_Hint: See [Section 4.3](http://runestone.academy/ns/books/published/thinkcspy/PythonTurtle/InstancesAHerdofTurtles.html){:target="_blank"} for setting the background color and [Lab 3](lab_03.html){:target="_blank"} for colors._
14) Due Date: 13 June Reading: Think CS Chapters 2 & 4
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 green 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: greenH.png
Sample input and resulting output files:
![](/127/csBridge.png) ![](/127/greenH.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() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
15) Due Date: 13 June Reading: Think CS Chapters 2 & 4
Write a program that implements the pseudocode 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,
Set n to be int(c)
Double decNum and add n to it (decNum = 2 * decNum + n)
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
Note: here's a quick [review](https://www.mathsisfun.com/binary-number-system.html){:target="_blank"} of binary numbers.
16) Due Date: 18 June Reading: Think CS Section 2.7
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 4](lab_04.html){:target="_blank"} for designing Input-Process-Output programs.
17) Due Date: 18 June Reading: Think CS Section 2.7 & 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](http://runestone.academy/ns/books/published/thinkcspy/SimplePythonData/OperatorsandOperands.html){:target="_blank"}._
18) Due Date: 18 June Reading: Think CS Chapters 4 & 7
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:
![](/127/5turns.png)
19) Due Date: 18 June Reading: Think CS Chapters 4 & 7
Modify the flood map of NYC from [Lab 4](lab_04.html) 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:
![](/127/floodMap2.png)
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() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
20) Due Date: 18 June Reading: Think CS: Section 8.10
Modify the map-making program from [Lab 4](lab_04.html) to create a map that outlines the coastline. Your program should create a new image, called coast.png with the pixels colored as follows:
* If the elevation is less than or equal to 0, color the pixel 50% blue (and 0% red and 0% green).
* If the elevation is exactly 1, color the pixel 75% red, 75% green, and 75% blue.
* Otherwise, the pixel should be colored 50% red, 50% green, and 50% blue.
Your resulting map should look like:
![](/127/coast.png)
and be saved to a file called coast.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() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
21) Due Date: 20 June Reading: Think CS Chapter 7
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 February 2014:
![](/127/CaliforniaDrought_02232014_md.png)
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.
_Hint: See [Lab 5](lab_05.html){:target="_blank"}_.
22) Due Date: 20 June 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.
![](/127/maj7.png)
Save your expression to a text file. See [Lab 5](lab5.html) for the format for submitting logical expressions to Gradescope.
23) Due Date: 20 June Reading: 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.
![](/127/norGate.png)
Save your expression to a text file. See [Lab 5](lab5.html) for the format for submitting logical expressions to Gradescope.
24) Due Date: 20 June Reading: Think CS Chapters 2 & 4
The program [turtleString.py](/127/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](https://code.org/curriculum/course2/1/Teacher){:target="_blank"}). 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
_Hint: See Lecture 4 notes._
25) Due Date: 20 June Reading: Think CS Chapter 4 & Section 7.4
Write a program that uses the turtle package to implement the following pseudocode:
1\. Ask the user for a whole number.
2\. If that number is even, your turtle should draw a blue line
towards the left hand side of the screen.
3\. If that number is odd, your turtle should draw a red line
towards the right hand side of the screen.
A sample run of your program should look like:
Enter a whole number: 2
and the output should look similar to:
![](/127/leftTurtle.png)
Another run:
Enter a whole number: -1
and the output should look similar to:
![](/127/rightTurtle.png)
_Hint: See [Section 7.4](http://runestone.academy/ns/books/published/thinkcspy/Selection/ConditionalExecutionBinarySelection.html){:target="_blank"} of the Python textbook and Lecture 4 notes._
26) Due Date: 23 June Reading: Numpy tutorial (DataCamp)**
Modify the program from [Lab 6](lab6.html){:target="_blank"} that displays the [NYC historical population data](/127/nycHistPop.csv). 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:
![](/127/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() 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: 23 June Reading: 10-mins to Pandas, DataCamp Pandas
Write a program that computes the 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](/127/nycHistPop.csv) is in the same directory.
A sample run of your program:
Enter borough: Staten Island
Average population: 139814.23076923078
Maximum population: 474558
and another run:
Enter borough: Brooklyn
Average population: 1252437.5384615385
Maximum population: 2738175
_Hint: See [Lab 6](lab_06.html){:target="_blank"}_.
28) Due Date: 23 June Reading: Think CS Chapter 7
Write a program that asks the user for the hour of the day (in 24 hour time), and prints
* "Good Morning" if it is strictly before 12,
* "Good Afternoon" if it is 12 or greater, but strictly before 17, and
* "Good Evening" otherwise.
A sample run:
Enter hour (in 24 hour time): 11
Good Morning
Another sample run:
Enter hour (in 24 hour time): 20
Good Evening
And another run:
Enter hour (in 24 hour time): 15
Good Afternoon
29) Due Date: 23 June 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 6](lab_06.html).
30) Due Date: 23 June 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`.
[![](/127/incrementCircuit.png)
(click to launch new window with circuit)](http://www.neuroproductions.be/logic-lab/index.php?id=80507){:target="_blank"}
Here is a table of the inputs and outputs:
| | Inputs | || | Outputs
Decimal<br/>Number | in1 | in2 || Decimal<br/>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: April 2017
#Logical expressions for a 4-bit incrementer
out1 = ...
out2 = ...
out3 = ...
Where `...` is replaced by your logical expression (see [Lab 5](lab5.html){:target="_blank"}).
31) Due Date: 25 June Reading: 10-mins to Pandas, DataCamp Pandas
Modify the program from [Lab 7](lab7.html){:target="_blank"} to:
* asks the user to specify the input file,
* asks the user to specify the output file,
* makes a plot of the fraction of the total population that are children over time from the data in input file, and
* stores 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:
![](/127/dhsPlot.png)
Note: The grading script is expecting that the label (i.e. name of your new column) is `"Fraction Children"`.
32) Due Date: 25 June Reading: Think CS Section 6.7
Write a program, using a function `main()` that prints `Hello, World!` to the screen. See [Lab 7](lab_07.html).
33) Due Date: 25 June Reading: Think CS Chapter 9
Write a program that asks the user for a list of nouns (separated by spaces) and approximates the fraction that are plural by counting the fraction that end in `s`. Your program should output the total number of words and the fraction that end in `s`. You may assume that words are separated by spaces (and ignore the possibility of tabs and punctuation between words.)
A sample run of the program:
Enter nouns: apple bananas cantaloupes durian
Number of words: 4
Fraction of your list that is plural is 0.5
And another sample run of the program:
Enter nouns: hats gloves coats glasses scarves
Number of words: 5
Fraction of your list that is plural is 1.0
_Hint: Break this problem into pieces:_
_* First, count the number of words in the string the user entered (hint: count the number of spaces). Print out the number of words. Make sure this works before going onto the next part.
* Next, ignoring the last word (which is a special case and can be dealt with separately), count the number of words ending in `s` (hint: count the number of `s`). Test that this part works before going on to the next step.
* Last, check the last word to see if it ends in `s`-- since it's the last word, the `s` will always occur at the same index in the string._
_Implement (and test!) each part and then go on to the next._
34) Due Date: 25 June Reading: Burch’s Logic & Circuits
Write a logical expression that takes a single input, in1, and **always** returns True. Your expression must only use in1 and the logical operators, and, or, and not
See [Lab 5](lab_05.html){:target="_blank"} for the format for submitting logical expressions to Gradescope.
_Hint: Think about the circuit below:_
![](/127/PorNotP.png)
35) *Due Date: 25 June**
Write a program that asks the user for the name of an image, the name of an output file. Your program should then save the lower left quarter of the image to the output file specified by the user.
A sample run of your program should look like:
Enter image file name: hunterLogo.png
Enter output file: logoLL.png
which would have as input and output:
![](/127/hunterLogo2.png) ![](/127/logoLL.png)
_Hint: See sample programs from Lectures 4 and 6._
Note: before submitting your program for grading, remove any 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()` commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
36) Due Date: 27 June Reading: 10-mins to Pandas, DataCamp Pandas
Modify the parking ticket program from [Lab 8](lab_08.html) 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: 27 June Reading: Github Guide
In [Lab 8](lab_08.html){:target="_blank"}, 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: April 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.
38) Due Date: 27 June Reading: Think CS Chapter 6
Fill in the missing function, monthString(), in the program, months.py (available at: [https://github.com/stjohn/csci127](https://github.com/stjohn/csci127)){:target="_blank"}. The function should take number between 1 and 12 as a parameter and returns the corresponding month as a string. For example, if the parameter is 1, your function should return `"January"`. If the parameter is `2`, your function should return out `"February"`, etc.
Note: The grading scripts are expecting that your function is called monthString(). 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 8](lab_08.html){:target="_blank"}._
39) Due Date: 27 June Reading: 10-mins to Pandas, DataCamp Pandas
Write a program that asks the user for a CSV of collision data (see note below about obtaining reported collisions from NYC OpenData). Your program should then list the top three contributing factors for the primary vehicle of collisions `"CONTRIBUTING FACTOR VEHICLE 1"` in the file.
A sample run:
Enter CSV file name: collisionsNewYears2016.csv
Top three contributing factors for collisions:
Driver Inattention/Distraction 136
Unspecified 119
Following Too Closely 37
Name: CONTRIBUTING FACTOR VEHICLE 1, dtype: int64
This assignment uses collision data collected and made publicly by [New York City Open Data](https://nycopendata.socrata.com){:target="_blank"}, and can be found at:
> [https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions/h9gi-nx95](https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions/h9gi-nx95){:target="_blank"}.
Since the files are quite large, use the "Filter" option and choose your birthday in 2016 and "Export" (in CSV format) all collisions for that day. We will use this data set for future programs, so, instead of downloading the test files multiple times, save a copy for future use.
_Hint: See [Lab 8](lab_08.html){:target="_blank"} for accessing and analyzing structured data._
40) Due Date: 27 June 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](https://github.com/stjohn/csci127). 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:
![](/127/triangles.png)
41) Due Date: 30 June 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 9](lab9.html){:target="_blank"}._
42) Due Date: 30 June Reading: Folium Tutorial
Using folium (see [Lab 9](lab9.html){:target="_blank"}), 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:
<iframe width="100%" height="600" frameborder="1" src="https://stjohn.github.io/teaching/csci127/f17/th.html"></iframe>
(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](https://nycopendata.socrata.com){:target="_blank"}. See Programming Problem #39 for details on this data set. 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")._
43) Due Date: 30 June Reading: Think CS Chapter 6 and Chapter 7
Write a function, `computeFare()`, that takes as two parameters: the zone and the ticket type, and returns the Long Island Railroad fare.
* If the zone is 1 and the ticket type is "peak", the fare is 8.75.
* If the zone is 1 and the ticket type is "off-peak", the fare is 6.25.
* If the zone is 2 or 3 and the ticket type is "peak", the fare is 10.25.
* If the zone is 2 or 3 and the ticket type is "off-peak", the fare is 7.50.
* If the zone is 4 and the ticket type is "peak", the fare is 12.00.
* If the zone is 4 and the ticket type is "off-peak", the fare is 8.75.
* If the zone is 5, 6, or 7 and the ticket type is "peak", the fare is 13.50.
* If the zone is 5, 6, or 7 and the ticket type is "off-peak", the fare is 9.75.
* If the zone is greater than 8, return a negative number (since your calculator does not handle inputs that high).
A template program, `LIRRtransit.py`, is available on the [CSci 127 repo on github](https://github.com/stjohn/csci127){:target="_blank"}. 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: 4
Enter the ticket type (peak/off-peak): off-peak
The fare is 8.75
And another:
Enter the number of zones: 6
Enter the ticket type (peak/off-peak): peak
The fare is 13.5
_Hint: See [Lab 8](lab_08.html){:target="_blank"}._
44) Due Date: 30 June Reading: Think CS: Chapter 6 and Folium Tutorial
Fill in the following functions in a program that maps GIS data from NYC OpenData CSV files and marks the current location and closest point:
* `getData()` that asks the user for the name of the CSV and returns a dataframe of the contents.
* `getColumnNames()` that asks the user for the exact name of the columns that contains the latitude and longitude and returns those values as a tuple. Since the NYC OpenData files use different names for the columns in different datasets (such as "Lat", "Latitude", "LATITUDE" for latitude), the program asks for the name of the column as well as the name of the data file.
* getLocale() asks the user for latitude and longitude of the user's current location and returns those floating points numbers.
* computeDist() that computes the squared distance between two points (x1,y1) and (x2,y2):
> (x1-x2)2 \+ (y1-y2)2
A sample run to find the closest CUNY campus to the Brooklyn Navy Yard:
Enter CSV file name: cunyLocations.csv
Enter column name for latitude: Latitude
Enter column name for longitude: Longitude
Enter current latitude: 40.7021
Enter current longitude: -73.9708
Enter output file: closestCUNY.html
which would produce the html file:
<iframe width="100%" height="600" frameborder="1" src="https://stjohn.github.io/teaching/csci127/f17/closestCUNY.html"></iframe>
Another sample run to find the closest recycling bin to Roosevelt Island, using the list of recycling bins [recyclingBins.csv](/127/recyclingBins.csv):
Enter CSV file name: recyclingBins.csv
Enter column name for latitude: Latitude
Enter column name for longitude: Longitude
Enter current latitude: 40.7605
Enter current longitude: -73.951
Enter output file: recyc.html
which would produce the html file:
<iframe width="100%" height="600" frameborder="1" src="https://stjohn.github.io/teaching/csci127/f17/recyc.html"></iframe>
A template program, is available here: [closestPoint.py](/127/closestPoint.py). 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 [Lab 9](lab_09.html){:target="_blank"}._
45) Due Date: 30 June Reading: Think CS: Chapter 6
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](http://koalastothemax.com){:target="_blank"}).
For example, if you inputted our favorite image, you would see (left to right):
![](/127/refined1.png) ![](/127/refined2.png) ![](/127/refined3.png) ![](/127/refined4.png) ![](/127/refined5.png) ![](/127/refined6.png) ![](/127/refined7.png) ![](/127/refined8.png)
and finally:
![](/127/csBridge.png)
A template program, averageImage.py, is available on the [CSci 127 repo on github](https://github.com/stjohn/csci127){:target="_blank"}. 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 9._
46) Due Date: 3 July Reading: Think CS: Chapter 3
Modify the program from [Lab 10](lab_10.html) that makes a turtle walk 100 times. Each "walk" is 10 steps forward and the turtle can turn 0, 1, 2, ..., 359 degrees (chosen randomly) at the beginning of each walk.
A sample run of your program:
![](/127/randomWalk.png)
47) Due Date: 3 July Reading: Think CS: Debugging Code
The program, [errorsHex.py](/127/errorsHex.py), has lots of errors. Fix the errors and submit the modified program.
_Hint: See [Lab 10](lab_10.html){:target="_blank"}._
48) Due Date: 3 July 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](lab_10.html){:target="_blank"}.
_Hint: See [Lab 10](lab_10.html){:target="_blank"}._
49) Due Date: 3 July Reading: MIPS Wikibooks
Write a simplified machine language program that prints: I love Python
See [Lab 11](lab_11.html){:target="_blank"} for details on submitting the simplified machine language programs.
Hint: You may find the following table useful:
![](https://stjohn.github.io/teaching/csci127/f17/ASCIITable.png){:target="_blank"}
50) Due Date: 3 July Reading: MIPS Wikibooks
Write a simplified machine language program that has register $s0 loop through the numbers 10, 8, 6, ..., 2, 0.
See [Lab 11](lab_11.html){:target="_blank"} for details on submitting the simplified machine language programs.
51) Due Date: 7 July Reading: Chapter 8
Write a program that asks the user to enter a string. If the user enters an empty string, your program should continue prompting the user for a new string until they enter a non-empty string. Your program should then print out the string entered.
A sample run of your program:
Enter a non-empty string:
That was empty. Try again.
Enter a non-empty string:
That was empty. Try again.
Enter a non-empty string: Mihi cura futuri
You entered: Mihi cura futuri
_Hint: See [Lab 10](lab_10.html){:target="_blank"}._
52) Due Date: 7 July 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 11](lab_11.html){:target="_blank"}._
53) Due Date: 7 July Reading: Cplusplus Tutorial
Write a **C++ program** that prints `Hello, World!` to the screen.
_Hint: See [Lab 12](lab_12.html){:target="_blank"} for getting started with C++._
54) Due Date: 7 July Reading: Cplusplus Tutorial
Write a **C++ program** that will print "I love Python!" 20 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!
_Hint: See [Lab 12](lab_12.html){:target="_blank"} for getting started with C++._
55) Due Date: 7 July Reading: Cplusplus Tutorial
Write a **C++ 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 4](lab_4.html){:target="_blank"} for designing Input-Process-Output programs and [Lab 12](lab_12.html){:target="_blank"} for getting started with C++.
56) *Due Date: 9 July** **Reading: Cplusplus Tutorial
Write a **C++ program** program that asks the user for a number and draws a triangle of that height and width using 'character graphics'.
A sample run:
Enter a number: 6
******
*****
****
***
**
*
Another sample run:
Enter a number: 3
***
**
*
57) *Due Date: 9 July** **Reading: Cplusplus Tutorial
Write a **C++ program** that asks the user for the month of the year (as a number), and prints
* "Happy Winter" if it is strictly before 3 or strictly larger than 11,
* "Happy Spring" if it is 3 or greater, but strictly before 7, and
* "Happy Summer" if it is 7 or greater, but strictly before 9, and
* "Happy Fall" otherwise.
A sample run:
Enter month (as a number): 12
Happy Winter
Another sample run:
Enter month (as a number): 8
Happy Summer
And another run:
Enter month (as a number): 11
Happy Fall
58) *Due Date: 9 July** **Reading: Cplusplus Tutorial
Write a **C++ program** that asks the user for the starting amount, and prints out the yearly balance of a savings account, assuming 10% interest, for the first five years.
A sample run:
Please enter the starting amount: 1000
Year 1 1100.00
Year 2 1210.00
Year 3 1331.00
Year 4 1464.10
Year 5 1610.51
59) *Due Date: 9 July** **Reading: Cplusplus Tutorial
Write a **C++ program** that asks the user for their age, and continue asking until the number entered positive (that is, greater than 0). That is, write the [Python program](http://pythontutor.com/visualize.html#code=age%20%3D%20int%28input%28'Please%20enter%20age%3A%20'%29%29%0Awhile%20age%20%3C%200%3A%0A%20%20%20%20print%28'Entered%20a%20negative%20number.'%29%0A%20%20%20%20age%20%3D%20int%28input%28'Please%20enter%20age%3A%20'%29%29%0Aprint%28'You%20entered%20your%20age%20as%3A',%20age%29&cumulative=false&curInstr=0&heapPrimitives=false&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%22-3%22,%223%22%5D&textReferences=false) from [Lab 10](lab10.html){:target="_blank"} in C++.
A sample run:
Please enter age: -6
Entered a negative number.
Please enter age: -50
Entered a negative number.
Please enter age: 100
You entered your age as: 100
_Hint: Rewrite the [Python program](http://pythontutor.com/visualize.html#code=age%20%3D%20int%28input%28'Please%20enter%20age%3A%20'%29%29%0Awhile%20age%20%3C%200%3A%0A%20%20%20%20print%28'Entered%20a%20negative%20number.'%29%0A%20%20%20%20age%20%3D%20int%28input%28'Please%20enter%20age%3A%20'%29%29%0Aprint%28'You%20entered%20your%20age%20as%3A',%20age%29&cumulative=false&curInstr=0&heapPrimitives=false&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%22-3%22,%223%22%5D&textReferences=false){:target="_blank"} from [Lab 10](lab10.html){:target="_blank"} in C++._
60) *Due Date: 9 July** **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](https://en.wikipedia.org/wiki/Two%27s_complement){:target="_blank"}" 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 2 July 2019.)