Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
20 changes: 13 additions & 7 deletions src/cityreader/cityreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ def cityreader(cities=[]):
# TODO Implement the functionality to read from the 'cities.csv' file
# For each city record, create a new City instance and add it to the
# `cities` list

# opens the csv file, saves it as csv_file
with open('cities.csv') as csv_file:
# reads csv file, separates by ,
read_csv = csv.reader(csv_file, delimiter=',')
lineNum = 0
# skips next line
next(read_csv)
# loops over each row, appends entry into cities[]
for row in read_csv:
if lineNum == 0:
lineNum += 1
else:
cities.append(City(row[0], float(row[3]), float(row[4])))
lineNum += 1

next(read_csv)
cities.append(City(row[0], float(row[3]), float(row[4])))
return cities


Expand Down Expand Up @@ -82,6 +83,11 @@ def cityreader(cities=[]):
# Salt Lake City: (40.7774,-111.9301)

# TODO Get latitude and longitude values from the user
# lat1 = input('Enter lat: ')
# lon1 = input('Enter lon: ')

# lat2 = input('Enter another lat: ')
# lon2 = input('Enter another lon: ')


def cityreader_stretch(lat1, lon1, lat2, lon2, cities=[]):
Expand Down
Binary file added src/comp/__pycache__/comp.cpython-37.pyc
Binary file not shown.
7 changes: 4 additions & 3 deletions src/comp/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ def __repr__(self):
# Write a list comprehension that creates a list of names of everyone
# whose name starts with 'D':
print("Starts with D:")
a = [human.name for human in humans if human.name[0] == 'D']
a = [human.name for human in humans if human.name[0].upper() == 'D']
print(a)

# Write a list comprehension that creates a list of names of everyone
# whose name ends in "e".
print("Ends with e:")
b = [human.name for human in humans if human.name.endswith('e')]
b = [human.name for human in humans if human.name.lower().endswith('e')]
print(b)

# Write a list comprehension that creates a list of names of everyone
# whose name starts with any letter between 'C' and 'G' inclusive.
print("Starts between C and G, inclusive:")
c = [human.name for human in humans if human.name[0] in ['C', 'D', 'E', 'F', 'G']]
c = [human.name for human in humans if human.name[0].upper() in [
'C', 'D', 'E', 'F', 'G']]
print(c)

# Write a list comprehension that creates a list of all the ages plus 10.
Expand Down
Binary file added src/oop/__pycache__/oop1.cpython-37.pyc
Binary file not shown.
Binary file added src/oop/__pycache__/oop2.cpython-37.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions src/oop/oop2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@


class GroundVehicle():
# change default num_wheels to 4 in constructor
def __init__(self, num_wheels=4):
self.num_wheels = num_wheels

# TODO
# added method called drive, returns vroom
def drive(self):
return 'vroooom'

Expand All @@ -21,9 +23,12 @@ def drive(self):
# Override the drive() method in Motorcycle so that it returns "BRAAAP!!"

# TODO
# create subclass Motorcycle
class Motorcycle(GroundVehicle):
def __init__(self):
# set num_wheels to 2 by passing to constructor of superclass
super().__init__(2)
# overwrite drive method, returns braap

def drive(self):
return "BRAAAP!!"
Expand All @@ -40,5 +45,6 @@ def drive(self):
# Go through the vehicles list and print the result of calling drive() on each.

# TODO
# for loop
for i in vehicles:
print(i.drive())