playLittleAlchemy()
in hw8.py:main()
to skip the game while you are focused on testing your code.
loadElementData(filename)
that takes in the file path to a data file stored in CSV (comma-separated values) format and returns a dictionary with the data from the file.Name | Icon |
---|---|
fire | https://littlealchemy.com/cheats/img/base/2.png |
earth | https://littlealchemy.com/cheats/img/base/2.png |
air | https://littlealchemy.com/cheats/img/base/2.png |
{ "fire":"https://littlealchemy.com/cheats/img/base/2.png", "earth":"https://littlealchemy.com/cheats/img/base/2.png", "air":"https://littlealchemy.com/cheats/img/base/2.png" }
loadReactionData(filename)
that takes in the file path to a data file stored in CSV format and returns a dictionary with the data from the file.Element1 | Element2 | Element3 |
---|---|---|
earth | fire | lava |
air | air | pressure |
air | fire | energy |
{ ("earth","fire"):"lava", ("air","air"):"pressure", ("air","fire"):"energy" }
tryReaction(elem1, elem2, reactionsDict)
that takes in strings elem1 and elem2 (element names) and returns the resulting element name (as a string) if elem1 and elem2 (in either order) lead to a reaction in the given reactionsDict. Return None if the two elements (in either order) don't lead to a reaction.
isTerminalElement(elem, reactionsDict)
that uses the reactionsDict to check if elem (element name string) reacts with any other element (including itself) to produce another element. The function returns True if elem is a "terminal element" and returns False otherwise. Note if the element doesn't appear anywhere in the reactionsDict, then the function returns True (i.e., this element doesn't technically react with anything, so it would be a "terminal element").
allNextElements(elementSet, reactionsDict)
that references the reactionsDict to create and return the set of all new elements (element name strings) that can be created directly from elements in current set, elementSet. Return an empty set if no more elements can be created.bestNextElement(elementSet, reactionsDict)
that references the reactionsDict to return the element name (string) that:
getPairSum([1], 1) == None
getPairSum([5, 2], 7) in [ (5, 2), (2, 5) ]
getPairSum([10, -1, 1, -8, 3, 1], 2) in [ (10, -8), (-8, 10), (-1, 3), (3, -1), (1, 1) ]
getPairSum([10, -1, 1, -8, 3, 1], 10) == None
{ ("Best Picture", "Green Book"), ("Best Actor", "Bohemian Rhapsody"), ("Best Actress", "The Favourite"), ("Film Editing", "Bohemian Rhapsody"), ("Best Original Score", "Black Panther"), ("Costume Design", "Black Panther"), ("Sound Editing", "Bohemian Rhapsody"), ("Best Director", "Roma") }the program should return:
{ "Black Panther" : 2, "Bohemian Rhapsody" : 3, "The Favourite" : 1, "Green Book" : 1, "Roma" : 1 }
Actor
and Movie
so that the following test code passes:
def testActorMovieClasses():
print('Testing Actor and Movie Classes...')
# Actor class
tom = Actor("Tom Hanks")
# Note that tom != "Tom Hanks" - one is an object, and the other is a string.
assert(isinstance(tom, Actor))
assert(tom.getName() == "Tom Hanks")
# Movie class
mrRogers = Movie("A Beatiful Day in the Neighborhood", 2019)
assert(isinstance(mrRogers, Movie))
assert(mrRogers.getTitle() == "A Beatiful Day in the Neighborhood")
assert(mrRogers.getYear() == 2019)
# Note: actor.getMovies() returns a list of Movie objects that
# that this actor is in, listed in the order that
# they were added. This will start off empty.
# Note: actor.getMovieTitles() returns a list of strings, the
# titles of the movies this actor was in. This list is sorted!
assert(tom.getMovies() == [])
assert(tom.getMovieTitles() == [])
# Similarly, getCast returns a list of Actor objects, while
# getCastNames returns a sorted list of Actor names
assert(mrRogers.getCast() == [])
assert(mrRogers.getCastNames() == [])
mrRogers.addActor(tom)
assert(mrRogers.getCast() == [tom])
assert(mrRogers.getCastNames() == ["Tom Hanks"])
# Adding an actor also updates the actor
assert(tom.getMovies() == [mrRogers])
assert(tom.getMovieTitles() == ["A Beatiful Day in the Neighborhood"])
diego = Actor("Diego Luna")
terminal = Movie("The Terminal", 2004)
terminal.addCast([tom, diego])
assert(terminal.getCast() == [tom, diego])
assert(terminal.getCastNames() == ["Diego Luna", "Tom Hanks"])
terminal.addActor(tom)
assert(terminal.getCast() == [tom, diego]) # Don't add twice
felicity = Actor("Felicity Jones")
rogue = Movie("Rogue One", 2016)
rogue.addCast([felicity, diego])
inferno = Movie("Inferno", 2016)
felicity.addMovie(inferno)
tom.addMovie(inferno)
assert(felicity.getMovies() == [rogue, inferno])
assert(tom.getMovieTitles() == ["A Beatiful Day in the Neighborhood",
"Inferno", "The Terminal"])
print('Passed!')