Repository navigation
Expand file tree
/
Copy pathobj.py
More file actions
39 lines (34 loc) · 1.53 KB
/
Copy pathobj.py
File metadata and controls
39 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Make a class LatLon that can be passed parameters `lat` and `lon` to the
# constructor
class LatLon:
def __init__(self, lat, lon):
self.lat = lat
self.lon = lon
# Make a class Waypoint that can be passed parameters `name`, `lat`, and `lon` to the
# constructor. It should inherit from LatLon.
class Waypoint(LatLon):
def __init__(self, name, lat, lon):
super().__init__(lat, lon)
self.name = name
# Make a class Geocache that can be passed parameters `name`, `difficulty`,
# `size`, `lat`, and `lon` to the constructor. What should it inherit from?
class GeoCache(Waypoint):
def __init__(self, difficulty, size, name, lat, lon):
super().__init__(name, lat, lon)
self.size = size
self.difficulty = difficulty
# Make a new waypoint "Catacombs", 41.70505, -121.51521
new_waypoint = Waypoint('Catacombs', 41.70505, -121.51521)
print(new_waypoint.name, new_waypoint.lat, new_waypoint.lon)
# Print it
#
# Without changing the following line, how can you make it print into something
# more human-readable?
w = "Name: " + str(new_waypoint.name) + "\n" + "Latitude: " + str(new_waypoint.lat) + "\n" + "Longitude: " + str(new_waypoint.lon)
print(w)
# Make a new geocache "Newberry Views", diff 1.5, size 2, 44.052137, -121.41556
geo = GeoCache("Newberry Views", "diff 1.5", "size 2", 44.052137, -121.41556)
print(geo.name)
g = "Name: {0}\nDifficulty: {1}\nSize: {2}\nLat: {3}\nLon: {4}\n".format(geo.name, geo.difficulty, geo.size, geo.lat, geo.lon)
# Print it--also make this print more nicely
print(g)