Last active
September 29, 2020 06:59
-
-
Save 7ranceaddic7/0ea97280000c95dfb6d92656dabe8948 to your computer and use it in GitHub Desktop.
The Borderless Tourist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
destinations = ["Paris, France", | |
"Shanghai, China", | |
"Los Angeles, USA", | |
"Sao Paulo, Brazil", | |
"Cairo, Egypt", | |
"Safety Catch"] | |
# TEST_DATA: traveler profile | |
test_traveler = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']] | |
print("\n====== ln" + str(inspect.currentframe().f_lineno) + ", destinations") | |
print(destinations) | |
# Get traveler destination index | |
def get_destination_index(destination): | |
try: | |
destination_index = destinations.index(destination) | |
except ValueError: | |
print("{} is not currently available)".format(destination)) | |
destination_index = 5 | |
return destination_index | |
return destination_index | |
# Get traveler's destination from profile | |
def get_traveler_location(traveler): | |
traveler_destination = traveler[1] | |
traveler_destination_index = get_destination_index(traveler_destination) | |
return traveler_destination_index | |
## TEST: functional unpacking | |
# def get_traveler_info(traveler_name, traveler_destination, traveler_likes): | |
# traveler_name = "" | |
# traveler_destination = "" | |
# traveler_likes = [] | |
# traveler_name = traveler_name | |
# traveler_destination = traveler_destination | |
# traveler_likes = traveler_likes | |
# return traveler_name, traveler_destination, traveler_likes | |
# print("\n=====ln" + str(inspect.currentframe().f_lineno) + ", get_traveler_info: ") | |
# print(get_traveler_info(*test_traveler)) | |
# Add attractions to destinations | |
attractions = [[] for destination in destinations] | |
def add_attraction(destination, attraction): | |
try: | |
destination_index = get_destination_index(destination) | |
except ValueError: | |
print("{destination} is not a valid destination.".format(destination=destination)) | |
return | |
attractions[destination_index].append(attraction) | |
return attractions | |
# TEST_DATA: destination attractions | |
add_attraction("Paris, France", ["the Louvre", ["art", "museum"]]) | |
add_attraction("Paris, France", ["Arc de Triomphe", ["historical site", "monument"]]) | |
add_attraction("Shanghai, China", ["Yu Garden", ["garden", "historical site"]]) | |
add_attraction("Shanghai, China", ["Yuz Museum", ["art", "museum"]]) | |
add_attraction("Shanghai, China", ["Oriental Pearl Tower", ["skyscraper", "viewing deck"]]) | |
add_attraction('Los Angeles, USA', ['Venice Beach', ['beach']]) | |
add_attraction("Los Angeles, USA", ["LACMA",["art", "museum"]]) | |
add_attraction("Sao Paulo, Brazil", ["Sao Paulo Zoo", ["zoo"]]) | |
add_attraction("Sao Paulo, Brazil", ["Patio do Colegio", ["historical site"]]) | |
add_attraction("Cairo, Egypt", ["Pyramids of Giza", ["monument", "historical site"]]) | |
add_attraction("Cairo, Egypt", ["Egyptian Museum", ["museum"]]) | |
print("\n====== ln" + str(inspect.currentframe().f_lineno) + ", attractions") | |
print(attractions) | |
# Lookup destination attractions | |
# def find_attractions(traveler="Peter Pan", destination="NeverNeverLand", interests="flying, lost boys"): | |
def find_attractions(destination, interests): | |
destination_index = get_destination_index(destination) | |
print("\n====== ln" + str(inspect.currentframe().f_lineno) + ", destination_index: ", end="") | |
print(destination_index) | |
attractions_in_city = attractions[destination_index] | |
print("\n====== ln" + str(inspect.currentframe().f_lineno) + ", List of attractions in {destination}:".format(destination=destination)) | |
print(attractions_in_city) | |
print("\n====== ln" + str(inspect.currentframe().f_lineno) + ", traveler interests:") | |
print(interests) | |
for attraction in attractions_in_city: | |
attractions_with_interests = [] | |
possible_attraction, attraction_tags = attraction | |
## unpacking result: ['LACMA'] | |
# possible_attraction = attraction | |
# attraction_tags = attraction[1] | |
## assigning result: [['LACMA', ['art', 'museum']]] | |
for interest in interests: | |
if interest in attraction_tags: | |
attractions_with_interests.append(possible_attraction) | |
print("\n====== ln" + str(inspect.currentframe().f_lineno) + ", List of possible attractions:") | |
print(interest) | |
print(attractions_with_interests) | |
return attractions_with_interests | |
# print(find_attractions(*test_traveler)) | |
la_arts = find_attractions("Los Angeles, USA",["art"]) | |
print("\n====== ln" + str(inspect.currentframe().f_lineno) + ", la_arts:") | |
print(la_arts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment