From 02bce97a4e570b9c4a09c339be91595e71adb764 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Aug 2018 12:20:13 -0400 Subject: [PATCH 1/8] Opening up branch and commit --- src/oop2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/oop2.py b/src/oop2.py index 04319ca909..9b7ca6906c 100644 --- a/src/oop2.py +++ b/src/oop2.py @@ -1,4 +1,5 @@ # To the GroundVehicle class, add method drive() that prints "vroooom". + # # Also change it so the num_wheels defaults to 4 if not specified when the # object is constructed. From da19143e6962430b76c442473d276fd850673215 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Aug 2018 12:38:56 -0400 Subject: [PATCH 2/8] csv method reads and prints correct data, and skips header --- Pipfile | 11 +++++++++++ src/cityreader.py | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 Pipfile diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000000..b9ba84f677 --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/src/cityreader.py b/src/cityreader.py index b3187edaf6..e4edc0805c 100644 --- a/src/cityreader.py +++ b/src/cityreader.py @@ -1,5 +1,12 @@ # Create a class to hold a city location. Call the class "City". It should have # fields for name, latitude, and longitude. +import csv + +class City: + def __init__( self, name, lat, lon ): + self.name = name + self.lat = lat + self.lon = lon # TODO @@ -18,6 +25,12 @@ cities = [] +with open('cities.csv') as csvfile: + csvCityData = csv.reader(csvfile, delimiter=',') + next(csvCityData) + for data in csvCityData: + print(data) + # TODO # Print the list of cities (name, lat, lon), 1 record per line. From 49c22a53c17caecead7776a28e699a5eab981ff0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Aug 2018 12:43:51 -0400 Subject: [PATCH 3/8] found state name, lat and lon --- src/cityreader.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cityreader.py b/src/cityreader.py index e4edc0805c..ef99bc680c 100644 --- a/src/cityreader.py +++ b/src/cityreader.py @@ -29,7 +29,10 @@ def __init__( self, name, lat, lon ): csvCityData = csv.reader(csvfile, delimiter=',') next(csvCityData) for data in csvCityData: - print(data) + print(data[0], "city") + print(data[3], "lat") + print(data[4], "lon") + # city = City() # TODO From 909b7e0d7970fc912b3bbda3fa57610c50099247 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Aug 2018 12:51:07 -0400 Subject: [PATCH 4/8] cityreader.py complete --- src/cityreader.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cityreader.py b/src/cityreader.py index ef99bc680c..557b8438fc 100644 --- a/src/cityreader.py +++ b/src/cityreader.py @@ -29,15 +29,20 @@ def __init__( self, name, lat, lon ): csvCityData = csv.reader(csvfile, delimiter=',') next(csvCityData) for data in csvCityData: - print(data[0], "city") - print(data[3], "lat") - print(data[4], "lon") - # city = City() + # print(data[0], "city") + # print(data[3], "lat") + # print(data[4], "lon") + city = City(data[0], data[3], data[4]) + cities.append(city) # TODO # Print the list of cities (name, lat, lon), 1 record per line. +# loop through list/ array usinf a for in + +for i in cities: + print(f'City {i.name}, Lattitude {i.lat}, Longitude {i.lon}') # TODO # *** STRETCH GOAL! *** From 5f640079eb582b0f0037c34461bf0207fa4533e2 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Aug 2018 13:08:56 -0400 Subject: [PATCH 5/8] comp.py between C and G is confusing, need to research --- src/comp.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/comp.py b/src/comp.py index c6d65f22ee..42c888db15 100644 --- a/src/comp.py +++ b/src/comp.py @@ -23,21 +23,22 @@ def __repr__(self): # whose name starts with 'D': print("Starts with D:") -r = [] # TODO +r = [ i.name for i in humans if i.name[0] == 'D' ] # TODO print(r) # Write a list comprehension that creates a list of names of everyone # whose name ends in "e". print("Ends with e:") -r = [] # TODO +# Need to split the string. If i.name[:-2] is last two character, then i.name[-1 is last character of string?] +r = [ i.name for i in humans if i.name[-1] == 'e' ] # TODO print(r) # 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:") -r = [] # TODO +r = [ i.name for i in humans if i.name[0] == 'C' or 'D' or 'E' or 'F' or 'G' ] # TODO print(r) # Write a list comprehension that creates a list of all the ages plus 10. From 3a57d5a2ae223d2c57e6556c725a590c83185dcf Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Aug 2018 13:14:09 -0400 Subject: [PATCH 6/8] Well, figured it out, thanks stack overflow, name starts between C and G inclusive --- src/comp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/comp.py b/src/comp.py index 42c888db15..6bb3f34877 100644 --- a/src/comp.py +++ b/src/comp.py @@ -38,7 +38,8 @@ def __repr__(self): # whose name starts with any letter between 'C' and 'G' inclusive. print("Starts between C and G, inclusive:") -r = [ i.name for i in humans if i.name[0] == 'C' or 'D' or 'E' or 'F' or 'G' ] # TODO +letters = ['C', 'D', 'E', 'F', 'G'] +r = [ i.name for i in humans if i.name[0] in letters ] # TODO print(r) # Write a list comprehension that creates a list of all the ages plus 10. From 57bdc9811c333d85c9b32be1f670ba54663b6ea0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Aug 2018 13:32:21 -0400 Subject: [PATCH 7/8] comp.py completed --- src/comp.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/comp.py b/src/comp.py index 6bb3f34877..f3014972c1 100644 --- a/src/comp.py +++ b/src/comp.py @@ -1,3 +1,5 @@ +import math + class Human: def __init__(self, name, age): self.name = name @@ -44,30 +46,34 @@ def __repr__(self): # Write a list comprehension that creates a list of all the ages plus 10. print("Ages plus 10:") -r = [] # TODO +r = [ i.age + 10 for i in humans ] # TODO print(r) # Write a list comprehension that creates a list of strings which are the name # joined to the age with a hyphen, for example "David-31", for all humans. print("Name hyphen age:") -r = [] # TODO +r = [ '{0}-{1}'.format(i.name, i.age) for i in humans ] # TODO print(r) # Write a list comprehension that creates a list of tuples containing name and # age, for example ("David", 31), for everyone between the ages of 27 and 32, # inclusive. print("Names and ages between 27 and 32:") -r = [] # TODO +ages = [27, 28, 29, 30, 31, 32] +r = [ ( i.name, i.age ) for i in humans if i.age in ages ] # TODO print(r) # Write a list comprehension that creates a list of new Humans like the old # list, except with all the names capitalized and the ages with 5 added to them. # The "humans" list should be unmodified. + +# Create new Humans class then? + print("All names capitalized:") -r = [] # TODO +r = [ Human( i.name.upper(), i.age + 5 ) for i in humans ] # TODO print(r) # Write a list comprehension that contains the square root of all the ages. print("Square root of ages:") -r = [] # TODO +r = [ math.sqrt(i.age) for i in humans ] # TODO print(r) \ No newline at end of file From 1fceef3e6a9ed32c7ddaa812eecaf3830df332aa Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Aug 2018 13:49:25 -0400 Subject: [PATCH 8/8] oop1 and oop2 completed --- src/oop1.py | 27 +++++++++++++++++++++++++++ src/oop2.py | 15 ++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/oop1.py b/src/oop1.py index b7268c5263..6546105e4f 100644 --- a/src/oop1.py +++ b/src/oop1.py @@ -17,3 +17,30 @@ # pass # # Put a comment noting which class is the base class + +class Vehicle: + pass + +class GroundVehicle(Vehicle): + pass + +class Car(GroundVehicle): + pass + +class Motorcycle(GroundVehicle): + pass + + + +# --------------------------------------------------------- + + + +class FlightVehicle: + pass + +class Airplane(FlightVehicle): + pass + +class Starship(FlightVehicle): + pass \ No newline at end of file diff --git a/src/oop2.py b/src/oop2.py index 9b7ca6906c..c6d6c47dc5 100644 --- a/src/oop2.py +++ b/src/oop2.py @@ -5,9 +5,12 @@ # object is constructed. class GroundVehicle(): - def __init__(self, num_wheels): + def __init__(self, num_wheels = 4): self.num_wheels = num_wheels + def drive(self): + print("vroooooooooooooooooooooooooom") + # TODO @@ -20,6 +23,13 @@ def __init__(self, num_wheels): # TODO +class Motorcycle(GroundVehicle): + def __init__( self, num_wheels = 2 ): + super().__init__( num_wheels ) + + def drive(self): + print("BRAAAAAP!!") + vehicles = [ GroundVehicle(), GroundVehicle(), @@ -30,4 +40,7 @@ def __init__(self, num_wheels): # Go through the vehicles list and call drive() on each. +for v in vehicles: + v.drive() + # TODO