<file_sep># 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. Look up the `super` method.

class Waypoint(LatLon):
    def __init__(self,name,lat,lon):
        super().__init__(lat,lon)
        self.name = name
    def __str__(self):
        return '''The waypoint {self.name} is located at Lat{self.lat},
    Lon{self.lon}'''.format(self=self)
#%%
# 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, name, difficulty, size, lat, lon):
        super().__init__(name,lat,lon)
        self.difficulty = difficulty
        self.size = size
    
    def __str__(self):
        return '''The cache {self.name} of size {self.size}
    is located at Lat{self.lat}, Lon{self.lon} with a difficulty of
                {self.difficulty}'''.format(self=self)
         
#%%
# Make a new waypoint and print it out: "Catacombs", 41.70505, -121.51521

Catacombs = Waypoint("Catacombs",41.70505,-121.51521)

print(Catacombs.name,Catacombs.lat,Catacombs.lon)
#%%
# Without changing the following line, how can you make it print into something
# more human-readable? Hint: Look up the `object.__str__` method
waypoint = Catacombs

print(waypoint)

# Make a new geocache "Newberry Views", diff 1.5, size 2, 44.052137, -121.41556

Newberry = Geocache("Newberry Views",1.5,2,44.052137, -121.41556)

# Print it--also make this print more nicely
geocache = Newberry.__str__()

print(geocache)
<file_sep>"""
Python makes performing file I/O simple. Take a look
at how to read and write to files here:

https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
"""

# Open up the "foo.txt" file (which already exists) for reading
# Print all the contents of the file, then close the file
# Note: pay close attention to your current directory when trying to open "foo.txt"

foo = open('foo.txt','r')

print(foo.read(-1))

foo.close()
#%%
# Open up a file called "bar.txt" (which doesn't exist yet) for
# writing. Write three lines of arbitrary content to that file,
# then close the file. Open up "bar.txt" and inspect it to make
# sure that it contains what you expect it to contain

bar = open("bar.txt",'w')

bar.write( """
This is an exercise in writing onto a text file.
I think this is interesting to do without modules.
Python has more power than I previously knew.
""")

bar.close()

rbar = open('bar.txt','r')

print(rbar.read(-1))

rbar.close()
