CSci 127: Introduction to Computer ScienceMore formally: git is a version control protocol for...

Post on 28-Sep-2020

3 views 0 download

transcript

CSci 127: Introduction to Computer Science

hunter.cuny.edu/csci

CSci 127 (Hunter) Lecture 7 10 March 2020 1 / 48

Announcements

Advising:

I Emely Peguero, department advisorI Hunter North 1090F Monday –

Wednesdays 9:00am-5:00pmI ep1950@hunter.cuny.edu

CS Survey:I Brian CampbellI Hunter Alumnus, class of 2019I Software Engineer at Seamless

CSci 127 (Hunter) Lecture 7 10 March 2020 2 / 48

Announcements

Advising:

I Emely Peguero, department advisorI Hunter North 1090F Monday –

Wednesdays 9:00am-5:00pmI ep1950@hunter.cuny.edu

CS Survey:I Brian CampbellI Hunter Alumnus, class of 2019I Software Engineer at Seamless

CSci 127 (Hunter) Lecture 7 10 March 2020 2 / 48

Today’s Topics

Recap: Slicing & Images

Introduction to Functions

NYC Open Data

CS Survey

CSci 127 (Hunter) Lecture 7 10 March 2020 3 / 48

Today’s Topics

Recap: Slicing & Images

Introduction to Functions

NYC Open Data

CS Survey

CSci 127 (Hunter) Lecture 7 10 March 2020 4 / 48

Challenge: Cropping Images

Crop an image to select the top quarter (upper left corner)

CSci 127 (Hunter) Lecture 7 10 March 2020 5 / 48

Challenge: Cropping Images

CSci 127 (Hunter) Lecture 7 10 March 2020 6 / 48

Challenge: Cropping Images

CSci 127 (Hunter) Lecture 7 10 March 2020 7 / 48

Challenge: Cropping Images

0 width

height

width/20

height/2

CSci 127 (Hunter) Lecture 7 10 March 2020 8 / 48

Challenge: Cropping Images

0 width

height

width/20

height/2

How would you select the lower left corner?img2 = img[height//2:, :width//2]

How would you select the upper right corner?img2 = img[:height//2, width//2:]

How would you select the lower right corner?img2 = img[height//2:, width//2:]

CSci 127 (Hunter) Lecture 7 10 March 2020 9 / 48

Challenge: Cropping Images

0 width

height

width/20

height/2

How would you select the lower left corner?

img2 = img[height//2:, :width//2]

How would you select the upper right corner?img2 = img[:height//2, width//2:]

How would you select the lower right corner?img2 = img[height//2:, width//2:]

CSci 127 (Hunter) Lecture 7 10 March 2020 9 / 48

Challenge: Cropping Images

0 width

height

width/20

height/2

How would you select the lower left corner?img2 = img[height//2:, :width//2]

How would you select the upper right corner?img2 = img[:height//2, width//2:]

How would you select the lower right corner?img2 = img[height//2:, width//2:]

CSci 127 (Hunter) Lecture 7 10 March 2020 9 / 48

Challenge: Cropping Images

0 width

height

width/20

height/2

How would you select the lower left corner?img2 = img[height//2:, :width//2]

How would you select the upper right corner?

img2 = img[:height//2, width//2:]

How would you select the lower right corner?img2 = img[height//2:, width//2:]

CSci 127 (Hunter) Lecture 7 10 March 2020 9 / 48

Challenge: Cropping Images

0 width

height

width/20

height/2

How would you select the lower left corner?img2 = img[height//2:, :width//2]

How would you select the upper right corner?img2 = img[:height//2, width//2:]

How would you select the lower right corner?img2 = img[height//2:, width//2:]

CSci 127 (Hunter) Lecture 7 10 March 2020 9 / 48

Challenge: Cropping Images

0 width

height

width/20

height/2

How would you select the lower left corner?img2 = img[height//2:, :width//2]

How would you select the upper right corner?img2 = img[:height//2, width//2:]

How would you select the lower right corner?

img2 = img[height//2:, width//2:]

CSci 127 (Hunter) Lecture 7 10 March 2020 9 / 48

Challenge: Cropping Images

0 width

height

width/20

height/2

How would you select the lower left corner?img2 = img[height//2:, :width//2]

How would you select the upper right corner?img2 = img[:height//2, width//2:]

How would you select the lower right corner?img2 = img[height//2:, width//2:]

CSci 127 (Hunter) Lecture 7 10 March 2020 9 / 48

Today’s Topics

Recap: Slicing & Images

Introduction to Functions

NYC Open Data

CS Survey

CSci 127 (Hunter) Lecture 7 10 March 2020 10 / 48

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 11 / 48

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 11 / 48

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 11 / 48

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:

Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 11 / 48

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 11 / 48

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,

which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 11 / 48

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 11 / 48

“Hello, World!” with Functions

CSci 127 (Hunter) Lecture 7 10 March 2020 12 / 48

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 7 10 March 2020 13 / 48

In Pairs or Triples:

Predict what the code will do:

CSci 127 (Hunter) Lecture 7 10 March 2020 14 / 48

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 7 10 March 2020 15 / 48

Input Parameters & Return Values

Functions can have inputparameters.

Surrounded by parentheses,both in the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 7 10 March 2020 16 / 48

Input Parameters & Return Values

Functions can have inputparameters.

Surrounded by parentheses,both in the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 7 10 March 2020 16 / 48

Input Parameters & Return Values

Functions can have inputparameters.

Surrounded by parentheses,both in the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 7 10 March 2020 16 / 48

Input Parameters & Return Values

Functions can have inputparameters.

Surrounded by parentheses,both in the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 7 10 March 2020 16 / 48

Input Parameters & Return Values

Functions can have inputparameters.

Surrounded by parentheses,both in the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 7 10 March 2020 16 / 48

Input Parameters & Return Values

Functions can have inputparameters.

Surrounded by parentheses,both in the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters.

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 7 10 March 2020 17 / 48

In Pairs or Triples:Circle the actual parameters and underline the formal parameters:

CSci 127 (Hunter) Lecture 7 10 March 2020 18 / 48

In Pairs or Triples:Circle the actual parameters and underline the formal parameters:

CSci 127 (Hunter) Lecture 7 10 March 2020 19 / 48

In Pairs or Triples:Predict what the code will do:

CSci 127 (Hunter) Lecture 7 10 March 2020 20 / 48

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 7 10 March 2020 21 / 48

In Pairs or Triples:

Predict what the code will do:

CSci 127 (Hunter) Lecture 7 10 March 2020 22 / 48

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 7 10 March 2020 23 / 48

In Pairs or Triples:

Fill in the missing code:

CSci 127 (Hunter) Lecture 7 10 March 2020 24 / 48

IDLE

(Demo with IDLE)

CSci 127 (Hunter) Lecture 7 10 March 2020 25 / 48

Github

Octocat

Used to collaborate on and share code,documents, etc.

Supporting Open-Source Software:original source code is made freelyavailable and may be redistributed andmodified.

More formally: git is a version controlprotocol for tracking changes and versionsof documents.

Github provides hosting for repositories(‘repos’) of code.

Also convenient place to host websites(i.e. huntercsci127.github.io).

In Lab6 you set up github accounts tocopy (‘clone’) documents from the classrepo. (More in future courses.)

CSci 127 (Hunter) Lecture 7 10 March 2020 26 / 48

Github

Octocat

Used to collaborate on and share code,documents, etc.

Supporting Open-Source Software:original source code is made freelyavailable and may be redistributed andmodified.

More formally: git is a version controlprotocol for tracking changes and versionsof documents.

Github provides hosting for repositories(‘repos’) of code.

Also convenient place to host websites(i.e. huntercsci127.github.io).

In Lab6 you set up github accounts tocopy (‘clone’) documents from the classrepo. (More in future courses.)

CSci 127 (Hunter) Lecture 7 10 March 2020 26 / 48

Github

Octocat

Used to collaborate on and share code,documents, etc.

Supporting Open-Source Software:original source code is made freelyavailable and may be redistributed andmodified.

More formally: git is a version controlprotocol for tracking changes and versionsof documents.

Github provides hosting for repositories(‘repos’) of code.

Also convenient place to host websites(i.e. huntercsci127.github.io).

In Lab6 you set up github accounts tocopy (‘clone’) documents from the classrepo. (More in future courses.)

CSci 127 (Hunter) Lecture 7 10 March 2020 26 / 48

Github

Octocat

Used to collaborate on and share code,documents, etc.

Supporting Open-Source Software:original source code is made freelyavailable and may be redistributed andmodified.

More formally: git is a version controlprotocol for tracking changes and versionsof documents.

Github provides hosting for repositories(‘repos’) of code.

Also convenient place to host websites(i.e. huntercsci127.github.io).

In Lab6 you set up github accounts tocopy (‘clone’) documents from the classrepo. (More in future courses.)

CSci 127 (Hunter) Lecture 7 10 March 2020 26 / 48

Github

Octocat

Used to collaborate on and share code,documents, etc.

Supporting Open-Source Software:original source code is made freelyavailable and may be redistributed andmodified.

More formally: git is a version controlprotocol for tracking changes and versionsof documents.

Github provides hosting for repositories(‘repos’) of code.

Also convenient place to host websites(i.e. huntercsci127.github.io).

In Lab6 you set up github accounts tocopy (‘clone’) documents from the classrepo. (More in future courses.)

CSci 127 (Hunter) Lecture 7 10 March 2020 26 / 48

Github

Octocat

Used to collaborate on and share code,documents, etc.

Supporting Open-Source Software:original source code is made freelyavailable and may be redistributed andmodified.

More formally: git is a version controlprotocol for tracking changes and versionsof documents.

Github provides hosting for repositories(‘repos’) of code.

Also convenient place to host websites(i.e. huntercsci127.github.io).

In Lab6 you set up github accounts tocopy (‘clone’) documents from the classrepo. (More in future courses.)

CSci 127 (Hunter) Lecture 7 10 March 2020 26 / 48

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 27 / 48

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:

Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 27 / 48

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 27 / 48

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,

which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 27 / 48

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 10 March 2020 27 / 48

Today’s Topics

Recap: Slicing & Images

Introduction to Functions

NYC Open Data

CS Survey

CSci 127 (Hunter) Lecture 7 10 March 2020 28 / 48

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 10 March 2020 29 / 48

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 10 March 2020 29 / 48

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 10 March 2020 29 / 48

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 10 March 2020 29 / 48

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 10 March 2020 29 / 48

Example: OpenData Film Permits

CSci 127 (Hunter) Lecture 7 10 March 2020 30 / 48

Example: OpenData Film Permits

What’s the most popular street for filming?

What’s the most popular borough?

How many TV episodes were filmed?

CSci 127 (Hunter) Lecture 7 10 March 2020 31 / 48

Example: OpenData Film Permits

What’s the most popular street for filming?

What’s the most popular borough?

How many TV episodes were filmed?

CSci 127 (Hunter) Lecture 7 10 March 2020 31 / 48

Example: OpenData Film Permits

What’s the most popular street for filming?

What’s the most popular borough?

How many TV episodes were filmed?

CSci 127 (Hunter) Lecture 7 10 March 2020 31 / 48

Example: OpenData Film Permits

Download the data as a CSV file and store on your computer.

Python program:

CSci 127 (Hunter) Lecture 7 10 March 2020 32 / 48

Example: OpenData Film Permits

Download the data as a CSV file and store on your computer.

Python program:

CSci 127 (Hunter) Lecture 7 10 March 2020 32 / 48

Example: OpenData Film Permits

Download the data as a CSV file and store on your computer.

Python program:

CSci 127 (Hunter) Lecture 7 10 March 2020 33 / 48

Example: OpenData Film Permits

Download the data as a CSV file and store on your computer.

Python program:

CSci 127 (Hunter) Lecture 7 10 March 2020 34 / 48

Example: OpenData Film Permits

Download the data as a CSV file and store on your computer.

Python program:

CSci 127 (Hunter) Lecture 7 10 March 2020 35 / 48

Example: OpenData Film Permits

Download the data as a CSV file and store on your computer.

Python program:

CSci 127 (Hunter) Lecture 7 10 March 2020 36 / 48

Example: OpenData Film Permits

Can approach the other questions in the same way:

What’s the most popular street for filming?

What’s the most popular borough?

How many TV episodes were filmed?

CSci 127 (Hunter) Lecture 7 10 March 2020 37 / 48

Design Question

Design an algorithm that finds the closest collision.

CSci 127 (Hunter) Lecture 7 10 March 2020 38 / 48

Design Question

Design an algorithm that finds the closest collision.

CSci 127 (Hunter) Lecture 7 10 March 2020 39 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).

2 Ask user for current location.3 Open up the CSV file.4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.

3 Open up the CSV file.4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.

4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance from each collision to user’s location.

5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance from each collision to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 10 March 2020 40 / 48

Today’s Topics

Recap: Slicing & Images

Introduction to Functions

NYC Open Data

CS Survey

CSci 127 (Hunter) Lecture 7 10 March 2020 41 / 48

CS Survey

Brian CampbellHunter Alumnus class of‘19Software Engineer at Seamless

CSci 127 (Hunter) Lecture 7 10 March 2020 42 / 48

Design Challenge

CSci 127 (Hunter) Lecture 7 10 March 2020 43 / 48

Design Challenge

Possible solutions:

I 7 orders of mixed fruit, orI 2 orders hot wings, 1 order mixed fruit, and 1 sampler plate.

Input: List of items with prices and amount to be spent.

Output: An order that totals to the amount or empty list if none.

Possible algorithms: For each item on the list, divide total by price. If noremainder, return a list of that item. Repeat with two items, trying 1 of thefirst, 2 of the first, etc. Repeat with three items, etc.

“NP-Complete” problem: possible answers can be checked quickly, but notknown how to compute quickly.

CSci 127 (Hunter) Lecture 7 10 March 2020 44 / 48

Design Challenge

Possible solutions:I 7 orders of mixed fruit, or

I 2 orders hot wings, 1 order mixed fruit, and 1 sampler plate.

Input: List of items with prices and amount to be spent.

Output: An order that totals to the amount or empty list if none.

Possible algorithms: For each item on the list, divide total by price. If noremainder, return a list of that item. Repeat with two items, trying 1 of thefirst, 2 of the first, etc. Repeat with three items, etc.

“NP-Complete” problem: possible answers can be checked quickly, but notknown how to compute quickly.

CSci 127 (Hunter) Lecture 7 10 March 2020 44 / 48

Design Challenge

Possible solutions:I 7 orders of mixed fruit, orI 2 orders hot wings, 1 order mixed fruit, and 1 sampler plate.

Input: List of items with prices and amount to be spent.

Output: An order that totals to the amount or empty list if none.

Possible algorithms: For each item on the list, divide total by price. If noremainder, return a list of that item. Repeat with two items, trying 1 of thefirst, 2 of the first, etc. Repeat with three items, etc.

“NP-Complete” problem: possible answers can be checked quickly, but notknown how to compute quickly.

CSci 127 (Hunter) Lecture 7 10 March 2020 44 / 48

Design Challenge

Possible solutions:I 7 orders of mixed fruit, orI 2 orders hot wings, 1 order mixed fruit, and 1 sampler plate.

Input: List of items with prices and amount to be spent.

Output: An order that totals to the amount or empty list if none.

Possible algorithms: For each item on the list, divide total by price. If noremainder, return a list of that item. Repeat with two items, trying 1 of thefirst, 2 of the first, etc. Repeat with three items, etc.

“NP-Complete” problem: possible answers can be checked quickly, but notknown how to compute quickly.

CSci 127 (Hunter) Lecture 7 10 March 2020 44 / 48

Design Challenge

Possible solutions:I 7 orders of mixed fruit, orI 2 orders hot wings, 1 order mixed fruit, and 1 sampler plate.

Input: List of items with prices and amount to be spent.

Output: An order that totals to the amount or empty list if none.

Possible algorithms: For each item on the list, divide total by price. If noremainder, return a list of that item. Repeat with two items, trying 1 of thefirst, 2 of the first, etc. Repeat with three items, etc.

“NP-Complete” problem: possible answers can be checked quickly, but notknown how to compute quickly.

CSci 127 (Hunter) Lecture 7 10 March 2020 44 / 48

Design Challenge

Possible solutions:I 7 orders of mixed fruit, orI 2 orders hot wings, 1 order mixed fruit, and 1 sampler plate.

Input: List of items with prices and amount to be spent.

Output: An order that totals to the amount or empty list if none.

Possible algorithms: For each item on the list, divide total by price. If noremainder, return a list of that item. Repeat with two items, trying 1 of thefirst, 2 of the first, etc. Repeat with three items, etc.

“NP-Complete” problem: possible answers can be checked quickly, but notknown how to compute quickly.

CSci 127 (Hunter) Lecture 7 10 March 2020 44 / 48

Design Challenge

Possible solutions:I 7 orders of mixed fruit, orI 2 orders hot wings, 1 order mixed fruit, and 1 sampler plate.

Input: List of items with prices and amount to be spent.

Output: An order that totals to the amount or empty list if none.

Possible algorithms: For each item on the list, divide total by price. If noremainder, return a list of that item. Repeat with two items, trying 1 of thefirst, 2 of the first, etc. Repeat with three items, etc.

“NP-Complete” problem: possible answers can be checked quickly, but notknown how to compute quickly.CSci 127 (Hunter) Lecture 7 10 March 2020 44 / 48

Today’s Topics

Recap: Slicing & Images

Introduction to Functions

NYC Open Data

CS Survey

CSci 127 (Hunter) Lecture 7 10 March 2020 45 / 48

Recap

On lecture slip, write down a topic you wishwe had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typing itsname, followed by any inputs, surrounded byparenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYC OpenData

Pass your lecture slips to the aisles for theUTAs to collect.

CSci 127 (Hunter) Lecture 7 10 March 2020 46 / 48

Recap

On lecture slip, write down a topic you wishwe had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typing itsname, followed by any inputs, surrounded byparenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYC OpenData

Pass your lecture slips to the aisles for theUTAs to collect.

CSci 127 (Hunter) Lecture 7 10 March 2020 46 / 48

Recap

On lecture slip, write down a topic you wishwe had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typing itsname, followed by any inputs, surrounded byparenthesis:

Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYC OpenData

Pass your lecture slips to the aisles for theUTAs to collect.

CSci 127 (Hunter) Lecture 7 10 March 2020 46 / 48

Recap

On lecture slip, write down a topic you wishwe had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typing itsname, followed by any inputs, surrounded byparenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYC OpenData

Pass your lecture slips to the aisles for theUTAs to collect.

CSci 127 (Hunter) Lecture 7 10 March 2020 46 / 48

Recap

On lecture slip, write down a topic you wishwe had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typing itsname, followed by any inputs, surrounded byparenthesis:Example: print("Hello", "World")

Can write, or define your own functions,

which are stored, until invoked or called.

Accessing Formatted Data: NYC OpenData

Pass your lecture slips to the aisles for theUTAs to collect.

CSci 127 (Hunter) Lecture 7 10 March 2020 46 / 48

Recap

On lecture slip, write down a topic you wishwe had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typing itsname, followed by any inputs, surrounded byparenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYC OpenData

Pass your lecture slips to the aisles for theUTAs to collect.

CSci 127 (Hunter) Lecture 7 10 March 2020 46 / 48

Recap

On lecture slip, write down a topic you wishwe had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typing itsname, followed by any inputs, surrounded byparenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYC OpenData

Pass your lecture slips to the aisles for theUTAs to collect.

CSci 127 (Hunter) Lecture 7 10 March 2020 46 / 48

Recap

On lecture slip, write down a topic you wishwe had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typing itsname, followed by any inputs, surrounded byparenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYC OpenData

Pass your lecture slips to the aisles for theUTAs to collect.

CSci 127 (Hunter) Lecture 7 10 March 2020 46 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:I write as much you can for 60 seconds;I followed by answer; andI repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:I write as much you can for 60 seconds;I followed by answer; andI repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:

I write as much you can for 60 seconds;I followed by answer; andI repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:I write as much you can for 60 seconds;

I followed by answer; andI repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:I write as much you can for 60 seconds;I followed by answer; and

I repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:I write as much you can for 60 seconds;I followed by answer; andI repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:I write as much you can for 60 seconds;I followed by answer; andI repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:I write as much you can for 60 seconds;I followed by answer; andI repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!

Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Practice Quiz & Final Questions

Since you must pass the final exam to pass the course, we end everylecture with final exam review.

Pull out something to write on (not to be turned in).

Lightning rounds:I write as much you can for 60 seconds;I followed by answer; andI repeat.

Past exams are on the webpage (under Final Exam Information).

Theme: Functions!Starting with Summer 18, #4.

CSci 127 (Hunter) Lecture 7 10 March 2020 47 / 48

Writing Boards

Return writing boards as you leave...

CSci 127 (Hunter) Lecture 7 10 March 2020 48 / 48