Skip to content
Snippets Groups Projects
Commit 06e86552 authored by LOUIS TYRRELL OLIPHANT's avatar LOUIS TYRRELL OLIPHANT
Browse files

added note on resources for learning

parent e24d5020
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Resources To Improve In The Course
* **CS 220 Office Hours** -- As I'm sure you know, you can go to the [course office hours](https://cs220.cs.wisc.edu/s24/schedule.html) to get help with labs and projects.
* **CS Learning Center** -- Offer free [small group tutoring](https://www.cs.wisc.edu/computer-sciences-learning-center-cslc/), not for debugging your programs, but to talk about course concepts.
* **Undergraduate Learning Center** -- Provides tutoring and [academic support](https://engineering.wisc.edu/student-services/undergraduate-learning-center/). They have [drop-in tutoring](https://intranet.engineering.wisc.edu/undergraduate-students/ulc/drop-in-tutoring/).
%% Cell type:markdown id: tags:
# Lists Practice
%% Cell type:markdown id: tags:
## Warmup
%% Cell type:code id: tags:
``` python
import csv
# source: Automate the Boring Stuff with Python Ch 12
def process_csv(filename):
exampleFile = open(filename, encoding="utf-8")
exampleReader = csv.reader(exampleFile)
exampleData = list(exampleReader)
exampleFile.close()
return exampleData
cs220_csv = process_csv('cs220_survey_data.csv')
cs220_header = cs220_csv[0]
cs220_data = cs220_csv[1:]
```
%% Cell type:code id: tags:
``` python
# Warmup 0: Hotkeys
# We move quickly, it's good to know some hotkeys!
# All-around good-to-knows...
# Ctrl+A: Select all the text in a cell.
# Ctrl+C: Copy selected text.
# Ctrl+X: Cut selected text.
# Ctrl+V: Paste text from clipboard.
# Ctrl+S: Save.
# Jupyter-specific good-to-knows...
# Ctrl+Enter: Run Cell
# Ctrl+/: Comment/uncomment sections of code.
# Esc->A: Insert cell above
# Esc->B: Insert cell below
# Esc->Shift+L: Toggle line numbers.
```
%% Cell type:code id: tags:
``` python
# Warmup 1: Empty List
weekend_plans = [] # I have no weekend plans :(
print(weekend_plans)
# TODO add three things to your weekend plans using .append
print(weekend_plans)
```
%% Cell type:code id: tags:
``` python
# Warmup 2: Sets
# Like a list, a set is another collection.
# However, it is unordered and unique.
# The function names are also a little different!
my_set_of_weekend_plans = set()
# .add() 4 weekend plans, 1 of which is a duplicate.
print(my_set_of_weekend_plans)
# We can .pop() (note no index as argument) ... but it will remove a random item.
# See https://www.w3schools.com/python/trypython.asp?filename=demo_ref_set_pop2
print(my_set_of_weekend_plans)
# We can .discard() a specific item!
# Unlike a list's remove, this will not throw an error if DNE (does not exist).
print(my_set_of_weekend_plans)
```
%% Cell type:code id: tags:
``` python
# Warmup 3: Improve the cell function...
def cell(row_idx, col_name):
col_idx = cs220_header.index(col_name)
val = cs220_data[row_idx][col_idx]
if val == "":
return None
elif col_name == "Age":
if "." in val or "," in val:
return None
return int(val)
else:
return val
```
%% Cell type:code id: tags:
``` python
# Warmup 4: Does the oldest basil/spinach-loving Business major prefer cats, dogs, or neither?
```
%% Cell type:code id: tags:
``` python
# Warmup 5: Is their favorite city in the United States?
# The United States has latitudes approximately spanning from 23.101 to 49.632
# and longitudes approximately spanning from -129.306 to -65.017
```
%% Cell type:markdown id: tags:
## Restaurants
%% Cell type:code id: tags:
``` python
restaurant_csv = process_csv('restaurants.csv')
# TODO: Display restaurant_csv. What do we call this data structure?
```
%% Cell type:code id: tags:
``` python
# TODO: Seperate the data into 2 parts...
# a header row, and a list of data rows
```
%% Cell type:code id: tags:
``` python
# TODO: Make a list of just the names from restaurant_data
names = [] # names starts out empty, we will append to it
for row in restaurant_data:
pass
names
```
%% Cell type:code id: tags:
``` python
# Convert names to a unique list of names
print(names)
# TODO Convert to a unique list of names
print(names)
```
%% Cell type:code id: tags:
``` python
# Sorting Option 1
print(names)
# TODO: Print the sorted list without changing it.
print(sorted(names))
```
%% Cell type:code id: tags:
``` python
# Sorting Option 2
print(names)
# TODO: Sort the list and print it
names.sort()
print(names)
```
%% Cell type:code id: tags:
``` python
# This is for our debugging sake.
restaurant_header
```
%% Cell type:code id: tags:
``` python
# This is for our debugging sake.
restaurant_data
```
%% Cell type:code id: tags:
``` python
# Define the cell function.
# If there is no data (""), return None
# Return x_coord and y_coord as an int.
# Return all other data as a string.
def cell(row_idx, col_name):
col_idx = restaurant_header.index(col_name)
val = restaurant_data[row_idx][col_idx]
if ???:
return None
elif ???:
return int(val)
else:
return val
```
%% Cell type:code id: tags:
``` python
# Write a function that is sent x y coordinates (ints)
# and returns back the restaurant_id of that restaurant.
def get_restaurant_at_coordinates(search_x, search_y):
for i in range(len(restaurant_data)):
pass
print(get_restaurant_at_coordinates(1, 3)) # should be EIN_1
print(get_restaurant_at_coordinates(0, -3)) # should be GRE_1
print(get_restaurant_at_coordinates(2, -3)) # should be None
```
%% Cell type:code id: tags:
``` python
# Write a function that is sent the restaurant ID of a
# restaurant and returns the x and y coordinates as a string
# This should be case-insensitive.
def get_coordinates(restaurant_id):
for i in range(len(restaurant_data)):
pass
print(get_coordinates("GRE_1")) # should be (0, -3)
print(get_coordinates("MCD_2")) # should be (2, 0)
print(get_coordinates("mcd_2")) # should be (2, 0)
print(get_coordinates("PAN_1")) # should be None
print(get_coordinates("ZZZ_123")) # should be None
```
%% Cell type:code id: tags:
``` python
# Define get_smallest_index to get the INDEX of the smallest value in col_name (such as 'x_coord')
# If there are ties, use the last value in the dataset.
def get_smallest_index(col_name):
pass
```
%% Cell type:code id: tags:
``` python
# What is the name of the restaurant farthest to the west?
```
%% Cell type:code id: tags:
``` python
# What is the business ID of the restaurant farthest to the south?
```
%% Cell type:code id: tags:
``` python
# Complete this function that computes the distance
# between (x1,y1) and (x2,y2)
import math
def distance(x1, y1, x2, y2):
pass
print(distance(0, 0, 3, 4)) # should be 5.0
print(distance(1, 2, 2, 3)) # should be square root of 2
print(distance(-3, 3, 2, -9)) # should be 13.0
```
%% Cell type:code id: tags:
``` python
# Write a function that is sent x and y coordinates and returns
# the name of the closest restaurant to those coordinates
# Use the distance formula to calculate distance.
def closest_restaurant(source_x, source_y):
'''return the name of the closest restaurant to the parameters given'''
closest_index = None # start with no value, to be clear if no result found
min_dist = None # why does this have to be None, not just 0?
for i in range(len(restaurant_data)):
current_x = cell(i, "x_coord")
current_y = cell(i, "y_coord")
if ???:
continue
current_dist = ???
if ???:
closest_index = i
min_dist = current_dist
# Why do we use index? Why not just name?
# Pretend that we instead have to get the business id!
return cell(closest_index, "name")
print(closest_restaurant(3, 3)) # should be Einsteins Bagels
print(closest_restaurant(0, 0)) # should be Starbucks
print(closest_restaurant(5, -2)) # should be McDonalds
print(closest_restaurant(1, -2)) # should be Greenbush Donuts
```
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment