Top Banner
CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 10 21 April 2020 1 / 33
90

CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Jul 31, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

CSci 127: Introduction to Computer Science

hunter.cuny.edu/csci

CSci 127 (Hunter) Lecture 10 21 April 2020 1 / 33

Page 2: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu barI Drop-in tutoring (12pm-5pm):

sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 10 21 April 2020 2 / 33

Page 3: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu barI Drop-in tutoring (12pm-5pm):

sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 10 21 April 2020 2 / 33

Page 4: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected]

I Discussion Board: on Blackboard, linkon purple menu bar

I Drop-in tutoring (12pm-5pm):sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 10 21 April 2020 2 / 33

Page 5: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu bar

I Drop-in tutoring (12pm-5pm):sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 10 21 April 2020 2 / 33

Page 6: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu barI Drop-in tutoring (12pm-5pm):

sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 10 21 April 2020 2 / 33

Page 7: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu barI Drop-in tutoring (12pm-5pm):

sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 10 21 April 2020 2 / 33

Page 8: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Today’s Topics

Recap: Folium

Indefinite loops

Design Patterns: Max (Min)

Design Challenge

CSci 127 (Hunter) Lecture 10 21 April 2020 3 / 33

Page 9: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Today’s Topics

Recap: Folium

Indefinite loops

Design Patterns: Max (Min)

Design Challenge

CSci 127 (Hunter) Lecture 10 21 April 2020 4 / 33

Page 10: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Challenge:What does this code do?

CSci 127 (Hunter) Lecture 10 21 April 2020 5 / 33

Page 11: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Folium example

What does this code do?

CSci 127 (Hunter) Lecture 10 21 April 2020 6 / 33

Page 12: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Folium example

What does this code do?

CSci 127 (Hunter) Lecture 10 21 April 2020 6 / 33

Page 13: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Folium

A module for making HTML maps.

It’s a Python interface to the popularleaflet.js.

Outputs .html files which you can open in abrowser.

An extra step:

Write ! Run ! Open .html

code. program. in browser.

CSci 127 (Hunter) Lecture 10 21 April 2020 7 / 33

Page 14: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Folium

A module for making HTML maps.

It’s a Python interface to the popularleaflet.js.

Outputs .html files which you can open in abrowser.

An extra step:

Write ! Run ! Open .html

code. program. in browser.

CSci 127 (Hunter) Lecture 10 21 April 2020 7 / 33

Page 15: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Folium

A module for making HTML maps.

It’s a Python interface to the popularleaflet.js.

Outputs .html files which you can open in abrowser.

An extra step:

Write ! Run ! Open .html

code. program. in browser.

CSci 127 (Hunter) Lecture 10 21 April 2020 7 / 33

Page 16: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Folium

A module for making HTML maps.

It’s a Python interface to the popularleaflet.js.

Outputs .html files which you can open in abrowser.

An extra step:

Write ! Run ! Open .html

code. program. in browser.

CSci 127 (Hunter) Lecture 10 21 April 2020 7 / 33

Page 17: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Folium

A module for making HTML maps.

It’s a Python interface to the popularleaflet.js.

Outputs .html files which you can open in abrowser.

An extra step:

Write ! Run ! Open .html

code. program. in browser.

CSci 127 (Hunter) Lecture 10 21 April 2020 7 / 33

Page 18: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Today’s Topics

Recap: Folium

Indefinite loops

Design Patterns: Max (Min)

Design Challenge

CSci 127 (Hunter) Lecture 10 21 April 2020 8 / 33

Page 19: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Challenge:

Write a function that asks a user for number after 2000 but before2018. The function should repeatedly ask the user for a number untilthey enter one within the range and return the number.

CSci 127 (Hunter) Lecture 10 21 April 2020 9 / 33

Page 20: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

CodingWrite a function that asks a user for number after 2000 but before2018. The function should repeatedly ask the user for a number untilthey enter one within the range and return the number..

CSci 127 (Hunter) Lecture 10 21 April 2020 10 / 33

Page 21: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

CodingWrite a function that asks a user for number after 2000 but before2018. The function should repeatedly ask the user for a number untilthey enter one within the range and return the number.

def getYear():

CSci 127 (Hunter) Lecture 10 21 April 2020 11 / 33

Page 22: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

CodingWrite a function that asks a user for number after 2000 but before2018. The function should repeatedly ask the user for a number untilthey enter one within the range and return the number.

def getYear():

return(num)

CSci 127 (Hunter) Lecture 10 21 April 2020 12 / 33

Page 23: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

CodingWrite a function that asks a user for number after 2000 but before2018. The function should repeatedly ask the user for a number untilthey enter one within the range and return the number.

def getYear():

num = 0

return(num)

CSci 127 (Hunter) Lecture 10 21 April 2020 13 / 33

Page 24: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

CodingWrite a function that asks a user for number after 2000 but before2018. The function should repeatedly ask the user for a number untilthey enter one within the range and return the number.

def getYear():

num = 0

while num <= 2000 or num >= 2018:

return(num)

CSci 127 (Hunter) Lecture 10 21 April 2020 14 / 33

Page 25: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

CodingWrite a function that asks a user for number after 2000 but before2018. The function should repeatedly ask the user for a number untilthey enter one within the range and return the number.

def getYear():

num = 0

while num <= 2000 or num >= 2018:

num = int(input(’Enter a number > 2000 & < 2018’))

return(num)

CSci 127 (Hunter) Lecture 10 21 April 2020 15 / 33

Page 26: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Indefinite Loops

Indefinite loops repeat as long asthe condition is true.

Could execute the body of theloop zero times, 10 times, infinitenumber of times.

The condition determines howmany times.

Very useful for checking input,simulations, and games.

CSci 127 (Hunter) Lecture 10 21 April 2020 16 / 33

Page 27: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Indefinite Loops

Indefinite loops repeat as long asthe condition is true.

Could execute the body of theloop zero times, 10 times, infinitenumber of times.

The condition determines howmany times.

Very useful for checking input,simulations, and games.

CSci 127 (Hunter) Lecture 10 21 April 2020 16 / 33

Page 28: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Indefinite Loops

Indefinite loops repeat as long asthe condition is true.

Could execute the body of theloop zero times, 10 times, infinitenumber of times.

The condition determines howmany times.

Very useful for checking input,simulations, and games.

CSci 127 (Hunter) Lecture 10 21 April 2020 16 / 33

Page 29: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Indefinite Loops

Indefinite loops repeat as long asthe condition is true.

Could execute the body of theloop zero times, 10 times, infinitenumber of times.

The condition determines howmany times.

Very useful for checking input,simulations, and games.

CSci 127 (Hunter) Lecture 10 21 April 2020 16 / 33

Page 30: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Indefinite Loops

Indefinite loops repeat as long asthe condition is true.

Could execute the body of theloop zero times, 10 times, infinitenumber of times.

The condition determines howmany times.

Very useful for checking input,simulations, and games.

CSci 127 (Hunter) Lecture 10 21 April 2020 16 / 33

Page 31: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Indefinite Loops

CSci 127 (Hunter) Lecture 10 21 April 2020 17 / 33

Page 32: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Indefinite Loops

CSci 127 (Hunter) Lecture 10 21 April 2020 17 / 33

Page 33: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

ChallengePredict what this code does:

CSci 127 (Hunter) Lecture 10 21 April 2020 18 / 33

Page 34: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Trinket Demo

(Demo with trinket)

CSci 127 (Hunter) Lecture 10 21 April 2020 19 / 33

Page 35: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Today’s Topics

Recap: Folium

Indefinite loops

Design Patterns: Max (Min)

Design Challenge

CSci 127 (Hunter) Lecture 10 21 April 2020 20 / 33

Page 36: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Patterns

A design pattern is a standard algorithmor approach for solving a commonproblem.

The pattern is independent of theprogramming language.

Can think of as a master recipe, withvariations for di↵erent situations.

CSci 127 (Hunter) Lecture 10 21 April 2020 21 / 33

Page 37: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Patterns

A design pattern is a standard algorithmor approach for solving a commonproblem.

The pattern is independent of theprogramming language.

Can think of as a master recipe, withvariations for di↵erent situations.

CSci 127 (Hunter) Lecture 10 21 April 2020 21 / 33

Page 38: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Patterns

A design pattern is a standard algorithmor approach for solving a commonproblem.

The pattern is independent of theprogramming language.

Can think of as a master recipe, withvariations for di↵erent situations.

CSci 127 (Hunter) Lecture 10 21 April 2020 21 / 33

Page 39: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Challenge:

Predict what the code will do:

CSci 127 (Hunter) Lecture 10 21 April 2020 22 / 33

Page 40: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 10 21 April 2020 23 / 33

Page 41: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Max Design Pattern

Set a variable to the smallest value.

Loop through the list,

If the current number is larger,update your variable.

Print/return the largest number found.

Similar idea works for finding theminimum value.

CSci 127 (Hunter) Lecture 10 21 April 2020 24 / 33

Page 42: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Max Design Pattern

Set a variable to the smallest value.

Loop through the list,

If the current number is larger,update your variable.

Print/return the largest number found.

Similar idea works for finding theminimum value.

CSci 127 (Hunter) Lecture 10 21 April 2020 24 / 33

Page 43: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Max Design Pattern

Set a variable to the smallest value.

Loop through the list,

If the current number is larger,update your variable.

Print/return the largest number found.

Similar idea works for finding theminimum value.

CSci 127 (Hunter) Lecture 10 21 April 2020 24 / 33

Page 44: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Max Design Pattern

Set a variable to the smallest value.

Loop through the list,

If the current number is larger,update your variable.

Print/return the largest number found.

Similar idea works for finding theminimum value.

CSci 127 (Hunter) Lecture 10 21 April 2020 24 / 33

Page 45: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Max Design Pattern

Set a variable to the smallest value.

Loop through the list,

If the current number is larger,update your variable.

Print/return the largest number found.

Similar idea works for finding theminimum value.

CSci 127 (Hunter) Lecture 10 21 April 2020 24 / 33

Page 46: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Pandas: Minimum Values

In Pandas, lovely built-in functions:

I df.sort values(’First Name’) andI df[’First Name’].min()

What if you don’t have a CSV and DataFrame, or data not ordered?

CSci 127 (Hunter) Lecture 10 21 April 2020 25 / 33

Page 47: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Pandas: Minimum Values

In Pandas, lovely built-in functions:I df.sort values(’First Name’) andI df[’First Name’].min()

What if you don’t have a CSV and DataFrame, or data not ordered?

CSci 127 (Hunter) Lecture 10 21 April 2020 25 / 33

Page 48: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Pandas: Minimum Values

In Pandas, lovely built-in functions:I df.sort values(’First Name’) andI df[’First Name’].min()

What if you don’t have a CSV and DataFrame, or data not ordered?

CSci 127 (Hunter) Lecture 10 21 April 2020 25 / 33

Page 49: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Question: Find first alphabetically

What if you don’t have a CSV and DataFrame, or data not ordered?

Useful Design Pattern: min/maxI Set a variable to worst value (i.e. maxN = 0 or first = "ZZ").I For each item, X, in the list:

F Compare X to your variable.

F If better, update your variable to be X.

I Print/return X.

CSci 127 (Hunter) Lecture 10 21 April 2020 26 / 33

Page 50: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Question: Find first alphabetically

What if you don’t have a CSV and DataFrame, or data not ordered?

Useful Design Pattern: min/max

I Set a variable to worst value (i.e. maxN = 0 or first = "ZZ").I For each item, X, in the list:

F Compare X to your variable.

F If better, update your variable to be X.

I Print/return X.

CSci 127 (Hunter) Lecture 10 21 April 2020 26 / 33

Page 51: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Question: Find first alphabetically

What if you don’t have a CSV and DataFrame, or data not ordered?

Useful Design Pattern: min/maxI Set a variable to worst value (i.e. maxN = 0 or first = "ZZ").

I For each item, X, in the list:F Compare X to your variable.

F If better, update your variable to be X.

I Print/return X.

CSci 127 (Hunter) Lecture 10 21 April 2020 26 / 33

Page 52: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Question: Find first alphabetically

What if you don’t have a CSV and DataFrame, or data not ordered?

Useful Design Pattern: min/maxI Set a variable to worst value (i.e. maxN = 0 or first = "ZZ").I For each item, X, in the list:

F Compare X to your variable.

F If better, update your variable to be X.

I Print/return X.

CSci 127 (Hunter) Lecture 10 21 April 2020 26 / 33

Page 53: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Question: Find first alphabetically

What if you don’t have a CSV and DataFrame, or data not ordered?

Useful Design Pattern: min/maxI Set a variable to worst value (i.e. maxN = 0 or first = "ZZ").I For each item, X, in the list:

F Compare X to your variable.

F If better, update your variable to be X.

I Print/return X.

CSci 127 (Hunter) Lecture 10 21 April 2020 26 / 33

Page 54: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Question: Find first alphabetically

What if you don’t have a CSV and DataFrame, or data not ordered?

Useful Design Pattern: min/maxI Set a variable to worst value (i.e. maxN = 0 or first = "ZZ").I For each item, X, in the list:

F Compare X to your variable.

F If better, update your variable to be X.

I Print/return X.

CSci 127 (Hunter) Lecture 10 21 April 2020 26 / 33

Page 55: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Question: Find first alphabetically

What if you don’t have a CSV and DataFrame, or data not ordered?

Useful Design Pattern: min/maxI Set a variable to worst value (i.e. maxN = 0 or first = "ZZ").I For each item, X, in the list:

F Compare X to your variable.

F If better, update your variable to be X.

I Print/return X.

CSci 127 (Hunter) Lecture 10 21 April 2020 26 / 33

Page 56: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Today’s Topics

Recap: Folium

Indefinite loops

Design Patterns: Max (Min)

Design Challenge

CSci 127 (Hunter) Lecture 10 21 April 2020 27 / 33

Page 57: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Collect all five stars (locations randomly generated):

CSci 127 (Hunter) Lecture 10 21 April 2020 28 / 33

Page 58: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 59: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, or

I Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 60: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 61: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 62: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 63: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 64: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 65: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.

I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 66: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.

I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 67: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.

I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 68: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Design Challenge

Possible approaches:

I Randomly wander until all 5 collected, orI Start in one corner, and systematically visit every point.

Input: The map of the ‘world.’

Output: Time taken and/or locations of the 5 stars.

How to store locations? Use numpy array with -1 everywhere.

Possible algorithms: while numStars < 5:

I Move forward.I If wall, mark 0 in map, randomly turn left or right.I If star, mark 1 in map and add 1 to numStars.I Otherwise, mark 2 in map that it’s an empty square.

CSci 127 (Hunter) Lecture 10 21 April 2020 29 / 33

Page 69: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Recap

Quick recap of a Python library, Folium for

creating interactive HTML maps.

More details on while loops for repeating

commands for an indefinite number of times.

Introduced the max design pattern.

CSci 127 (Hunter) Lecture 10 21 April 2020 30 / 33

Page 70: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Recap

Quick recap of a Python library, Folium for

creating interactive HTML maps.

More details on while loops for repeating

commands for an indefinite number of times.

Introduced the max design pattern.

CSci 127 (Hunter) Lecture 10 21 April 2020 30 / 33

Page 71: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Recap

Quick recap of a Python library, Folium for

creating interactive HTML maps.

More details on while loops for repeating

commands for an indefinite number of times.

Introduced the max design pattern.

CSci 127 (Hunter) Lecture 10 21 April 2020 30 / 33

Page 72: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

This course has three main themes:I Programming & Problem Solving

I Organization of Hardware & DataI Design

The operating system, Unix, is part ofthe second theme.

Unix commands in the weekly on-linelabs

CSci 127 (Hunter) Lecture 10 21 April 2020 31 / 33

Page 73: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

This course has three main themes:I Programming & Problem SolvingI Organization of Hardware & Data

I Design

The operating system, Unix, is part ofthe second theme.

Unix commands in the weekly on-linelabs

CSci 127 (Hunter) Lecture 10 21 April 2020 31 / 33

Page 74: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

This course has three main themes:I Programming & Problem SolvingI Organization of Hardware & DataI Design

The operating system, Unix, is part ofthe second theme.

Unix commands in the weekly on-linelabs

CSci 127 (Hunter) Lecture 10 21 April 2020 31 / 33

Page 75: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

This course has three main themes:I Programming & Problem SolvingI Organization of Hardware & DataI Design

The operating system, Unix, is part ofthe second theme.

Unix commands in the weekly on-linelabs

CSci 127 (Hunter) Lecture 10 21 April 2020 31 / 33

Page 76: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

This course has three main themes:I Programming & Problem SolvingI Organization of Hardware & DataI Design

The operating system, Unix, is part ofthe second theme.

Unix commands in the weekly on-linelabs

CSci 127 (Hunter) Lecture 10 21 April 2020 31 / 33

Page 77: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 78: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 79: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 80: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 81: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 82: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 83: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 84: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 85: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 86: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 87: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 88: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 89: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Final Exam Prep: UNIX

xkcd 149

Unix commands in the weekly on-line labs:

Lab 2: pwd, ls, mkdir, cd

Lab 3: ls -l, cp, mv

Lab 4: cd ../ (relative paths)

Lab 5: cd /usr/bin (absolute paths), cd ⇠

Lab 6: Scripts, chmod

Lab 7: Running Python from the command line

Lab 8: git from the command line

Lab 9: ls *.py (wildcards)

Lab 10: More on scripts, vim

Lab 11: ls | wc -c (pipes), grep, wc

Lab 12: file, which

Lab 13: man, more, w

CSci 127 (Hunter) Lecture 10 21 April 2020 32 / 33

Page 90: CSci 127: Introduction to Computer Science · It’s a Python interface to the popular leaflet.js. Outputs .html files which you can open in a browser. An extra step: Write ! Run

Educational Psychology Study

If you have consented to participate in the

Educational Psychology study,

please fill in the 3-question survey

Clickable link also below the video.

Thank you for your participation!!!

CSci 127 (Hunter) Lecture 10 21 April 2020 33 / 33