From d2115a120b31fe6ad62dd26c5dca1bbc611c329e Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Thu, 8 Apr 2021 16:48:48 -0600 Subject: [PATCH 1/4] oop1 set up --- src/oop/oop1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/oop/oop1.py b/src/oop/oop1.py index b7268c5263..355a947467 100644 --- a/src/oop/oop1.py +++ b/src/oop/oop1.py @@ -17,3 +17,30 @@ # pass # # Put a comment noting which class is the base class + +#This is the base class. +class Vehicle: + def __init__(self, name, year): + self.name = name + self.year = year + +class FlightVehicle(Vehicle): + pass + +class GroundVehicle(Vehicle): + pass + +class Starship(FlightVehicle): + pass + +class Airplane(FlightVehicle): + pass + +class Car(GroundVehicle): + pass + +class Motorcycle(GroundVehicle): + pass + + + From fe1959c95c0e367fcda9e9907f844a2a93d7bdc9 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Thu, 8 Apr 2021 21:46:13 -0600 Subject: [PATCH 2/4] list comprehensions started --- src/cityreader/cityreader.py | 5 ++++- src/comp/comp.py | 14 +++++++++----- src/oop/oop2.py | 5 ++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/cityreader/cityreader.py b/src/cityreader/cityreader.py index 2bd8007ce7..be8dc8a3ef 100644 --- a/src/cityreader/cityreader.py +++ b/src/cityreader/cityreader.py @@ -1,6 +1,9 @@ # Create a class to hold a city location. Call the class "City". It should have # fields for name, lat and lon (representing latitude and longitude). - +class City(): + def __init__(self, lat, lon): + self.lat = lat + self.lon = lon # We have a collection of US cities with population over 750,000 stored in the # file "cities.csv". (CSV stands for "comma-separated values".) diff --git a/src/comp/comp.py b/src/comp/comp.py index 82f8821d63..1a79cf4b60 100644 --- a/src/comp/comp.py +++ b/src/comp/comp.py @@ -20,34 +20,38 @@ def __repr__(self): Human("Igon", 41), Human("David", 31), ] +#need some way to separate names from ages # Write a list comprehension that creates a list of names of everyone # whose name starts with 'D': print("Starts with D:") -a = [] +a = [x for x in humans if x[0] == '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 = [] +b = [x for x in humans if x[-1] == '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 = [] +import string +string.ascii_uppercase +c = [x for x in humans if string.ascii_uppercase[2] <= x[0] <= string.ascii_uppercase[6]] print(c) # Write a list comprehension that creates a list of all the ages plus 10. print("Ages plus 10:") -d = [] +d = [n+10 for n in humans] print(d) # 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. +#something sort of like this print("Name hyphen age:") -e = [] +e = [x-n for x, n in humans] print(e) # Write a list comprehension that creates a list of tuples containing name and diff --git a/src/oop/oop2.py b/src/oop/oop2.py index 29d3e481fe..df94c2ed7d 100644 --- a/src/oop/oop2.py +++ b/src/oop/oop2.py @@ -5,8 +5,11 @@ class GroundVehicle(): def __init__(self, num_wheels): + if not num_wheels: + return 4 self.num_wheels = num_wheels - + def drive(): + return 'vrooooom' # TODO From 86c052dc5d882b27b288e30addd6a305e875558b Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Thu, 8 Apr 2021 22:25:19 -0600 Subject: [PATCH 3/4] pseduo coding it --- src/comp/comp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/comp/comp.py b/src/comp/comp.py index 1a79cf4b60..f67666ed40 100644 --- a/src/comp/comp.py +++ b/src/comp/comp.py @@ -65,11 +65,11 @@ def __repr__(self): # list, except with all the names uppercase and the ages with 5 added to them. # The "humans" list should be unmodified. print("All names uppercase:") -g = [] +g = [uppercase(n), x+5 for x, n in humans] print(g) # Write a list comprehension that contains the square root of all the ages. print("Square root of ages:") import math -h = [] +h = [sqrt(x) for x in humans] print(h) From beecba14c01735177676e7cabe4d59a7ff22f440 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Fri, 9 Apr 2021 11:58:06 -0600 Subject: [PATCH 4/4] lc updated --- src/comp/comp.py | 18 +++++++++--------- src/oop/oop2.py | 7 +++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/comp/comp.py b/src/comp/comp.py index f67666ed40..9209124ad7 100644 --- a/src/comp/comp.py +++ b/src/comp/comp.py @@ -25,51 +25,51 @@ 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 = [x for x in humans if x[0] == 'D'] +a = [x for x in humans.name if x[0] == '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 = [x for x in humans if x[-1] == 'e'] +b = [x for x in humans.name if x[-1] == '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:") import string -string.ascii_uppercase -c = [x for x in humans if string.ascii_uppercase[2] <= x[0] <= string.ascii_uppercase[6]] +alphabet = string.ascii_uppercase +c = [x for x in humans.name if alphabet[2] <= x[0] <= alphabet[6]] print(c) # Write a list comprehension that creates a list of all the ages plus 10. print("Ages plus 10:") -d = [n+10 for n in humans] +d = [humans.age[i] + 10 for i in humans] print(d) # 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. #something sort of like this print("Name hyphen age:") -e = [x-n for x, n in humans] +e = [' '.join(humans[i].name-humans[i].age) for i in humans] print(e) # 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:") -f = [] +f = [humans[i].name, humans[i].age for i in range(32 <= humans.age <= 27)] print(f) # Write a list comprehension that creates a list of new Humans like the old # list, except with all the names uppercase and the ages with 5 added to them. # The "humans" list should be unmodified. print("All names uppercase:") -g = [uppercase(n), x+5 for x, n in humans] +g = [humans[i].name.captialize(), humans[i].age + 5 for i in humans] print(g) # Write a list comprehension that contains the square root of all the ages. print("Square root of ages:") import math -h = [sqrt(x) for x in humans] +h = [math.sqrt(humans[i].age) for i in humans] print(h) diff --git a/src/oop/oop2.py b/src/oop/oop2.py index df94c2ed7d..03ee8c7590 100644 --- a/src/oop/oop2.py +++ b/src/oop/oop2.py @@ -20,6 +20,12 @@ def drive(): # # Override the drive() method in Motorcycle so that it returns "BRAAAP!!" +class Motorcycle(GroundVehicle): + super().__init__(self, 2) + #something like that + def drive(self): + return 'BRAAAP!!' + # TODO vehicles = [ @@ -33,3 +39,4 @@ def drive(): # Go through the vehicles list and print the result of calling drive() on each. # TODO +