for type in types: food_categories.insert(type) #Write code to insert restaurant data into a data structure here. The data is in data.py restaurant_directory = HashMap(len(types)) for type in types: restaurant_directory.assign(type, LinkedList()) for i in restaurant_data: business_hash = HashMap(len(i)-1) business_hash.assign('name',i[1]) business_hash.assign('price',i[2]) business_hash.assign('rating',i[3]) business_hash.assign('address',i[4]) restaurant_directory.retrieve(i[0]).insert_beginning(business_hash) #print(restaurant_directory.array) #Write code for user interaction here while True: user_input = str(input("\nWhat type of food would you like to eat?\nType the beginning of that food type and press enter to see if it's here.\n")).lower() #Search for user_input in food types data structure here results = food_categories.search(user_input) if len(results) > 1: print("\nWith those beginning letters, your choices are {}".format(sorted(results))) elif len(results) == 0: print("No categories begin with '{}'. Please try again.".format(user_input)) elif len(results) == 1:
my_hashmap.assign("Elise", "Severe Nausea") my_hashmap.assign("Mimi", "Stomach Flu") my_hashmap.assign("Devan", "Malaria") my_hashmap.assign("Gary", "Bacterial Meningitis") my_hashmap.assign("Neeknaz", "Broken Cheekbone") #Insert Data into LinkedList my_linked_list = LinkedList(["Zachary", "Sunburn Sickness"]) my_linked_list.insert_beginning(["Elise", "Severe Nausea"]) my_linked_list.insert_beginning(["Mimi", "Stomach Flu"]) my_linked_list.insert_beginning(["Devan", "Malaria"]) my_linked_list.insert_beginning(["Gary", "Bacterial Meningitis"]) my_linked_list.insert_beginning(["Neeknaz", "Broken Cheekbone"]) #Get Zachary's Disease from a HashMap hashmap_zachary_disease = my_hashmap.retrieve("Zachary") #Checkpoint 1 print("Zachary's disease is {0}".format(hashmap_zachary_disease)) hashmap_runtime = "1" #Checkpoint 2 print("The runtime of retrieving a value from a hashmap is O({0})\n\n".format(hashmap_runtime)) #Get Zachary's Disease from a Linked List #Write Code here for Checkpoint 3 current_node = my_linked_list.get_head_node() while current_node.get_value()[0] != "Zachary": current_node = current_node.get_next_node() linked_list_zachary_disease = current_node.get_value()[1] print("Zachary's disease is {0}".format(linked_list_zachary_disease)) linked_list_runtime = "N" #Checkpoint 4 print("The runtime of retrieving the first value added to a linked list is O({0})\n\n".format(linked_list_runtime))
# Entering cuisine data food_types = Trie() eateries = HashMap(len(types)) for food in types: food_types.add(food) eateries.assign(food, LinkedList()) # restaurant data-point key names: eatery_cuisine = "cuisine" eatery_name = "name" eatery_price = "price" eatery_rating = "rating" eatery_address = "address" # Entering restaurant data for restaurant in restaurant_data: current_eateries_for_cuisine = eateries.retrieve(restaurant[0]) current_eatery_data = HashMap(len(restaurant)) current_eatery_data.assign(eatery_cuisine, restaurant[0]) current_eatery_data.assign(eatery_name, restaurant[1]) current_eatery_data.assign(eatery_price, restaurant[2]) current_eatery_data.assign(eatery_rating, restaurant[3]) current_eatery_data.assign(eatery_address, restaurant[4]) if current_eateries_for_cuisine.get_head_node().get_value() is None: current_eateries_for_cuisine.get_head_node( ).value = current_eatery_data else: current_eateries_for_cuisine.insert_beginning(current_eatery_data) # Begin user interaction logic quit_code = "quit!"
from trie import Trie from data import * from welcome import * from hashmap import HashMap from linkedlist import LinkedList #Printing the Welcome Message print_welcome() #Write code to insert food types into a data structure here. The data is in data.py userChoice = HashMap(len(types)) for type in types: if userChoice.retrieve(type[0]) is None: ll = LinkedList(type) userChoice.assign(type[0], ll) else: ll = userChoice.retrieve(type[0]) ll.insert_beginning(type) userChoice.assign(type[0], ll) # Write code to insert restaurant data into a data structure here. The data is in data.py restaurantChoice = HashMap(len(restaurant_data)) for restaurant in restaurant_data: if restaurantChoice.retrieve(restaurant[0]) is None: ll = LinkedList(restaurant[1:6]) restaurantChoice.assign(restaurant[0], ll) else: ll = restaurantChoice.retrieve(restaurant[0]) ll.insert_beginning(restaurant[1:6]) restaurantChoice.assign(restaurant[0], ll)
my_hashmap.assign("Elise", "Severe Nausea") my_hashmap.assign("Mimi", "Stomach Flu") my_hashmap.assign("Devan", "Malaria") my_hashmap.assign("Gary", "Bacterial Meningitis") my_hashmap.assign("Neeknaz", "Broken Cheekbone") # Insert Data into LinkedList my_linked_list = LinkedList(["Zachary", "Sunburn Sickness"]) my_linked_list.insert_beginning(["Elise", "Severe Nausea"]) my_linked_list.insert_beginning(["Mimi", "Stomach Flu"]) my_linked_list.insert_beginning(["Devan", "Malaria"]) my_linked_list.insert_beginning(["Gary", "Bacterial Meningitis"]) my_linked_list.insert_beginning(["Neeknaz", "Broken Cheekbone"]) # Get Zachary's Disease from a HashMap hashmap_zachary_disease = my_hashmap.retrieve("Zachary") print("Zachary's disease is {0}".format(hashmap_zachary_disease)) hashmap_runtime = "1" print("The runtime of retrieving a value from a hashmap is O({0})\n\n".format( hashmap_runtime)) # Get Zachary's Disease from a Linked List traverse = my_linked_list.get_head_node() while traverse.get_value()[0] != "Zachary": traverse = traverse.get_next_node() linked_list_zachary_disease = traverse.get_value()[1] print("Zachary's disease is {0}".format(linked_list_zachary_disease)) linked_list_runtime = "N" print( "The runtime of retrieving the first value added to a linked list is O({0})\n\n" .format(linked_list_runtime))
def main(): m = HashMap() m.load_package_details("package_details.txt", m) d = Distance() d.load_distances('node_list.txt', 'combo.txt', d) t = Truck() truck_1_packages, truck_2_packages, truck_3_packages = t.prep_trucks() all_packages = combine_lists(truck_1_packages, truck_2_packages, truck_3_packages) print print(42 * "-") print("Data Structures and Algorithms 2 - C950") print(13 * " " + "Rob Muhlestein") print(42 * "-") print(30 * '-') print(6 * " " + "M A I N - M E N U") print(30 * '-') print("1. Lookup package details (ID input & Time input") print("2. Lookup package details (Address input & Time input") print("3. Run Delivery Simulation - Input Time") print("4. Print Delivery Report (ID# & Status Only) - Input Time") print(30 * '-') ## Get Input ### choice = raw_input() ### Take action as per selected menu-option ## if choice == '1': # lookup package details (ID and time input) print("Preparing Simulation...") for packages in all_packages: m.retrieve(packages) print user_time = raw_input( "What time would you like to simulate? \n (24 hr format e.g. 0900, 1315): " ) if len(user_time) != 4 or ":" in user_time: # raise error message if time entered is not in a useable format raise ValueError( "Entry: {} is not a valid entry.\n\tPlease ensure the time you enter is in the format '0000'. E.g. 0900.\n\tDo not include ':' or 'AM' or 'PM'." .format(user_time)) else: if user_time[-2:] > '59': # raise error message if time entered isn't a valid time raise ValueError( 'Entry: {} -- minutes > 59 is not a valid time entry.'. format(user_time)) else: inquiry_ID = raw_input("Enter ID#: ") elapsed_time = convert_time(user_time) if elapsed_time < 65: # 0905 # 0800- all trucks get loaded # Truck 1, having the highest priority packages, # leaves first truck_1 = t.load_truck(m, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) send_1(m, elapsed_time, distances_1, truck_1) print("\nPrinting Package Info for {}".format(inquiry_ID)) key, vals = m.retrieve(inquiry_ID) print("{}: {}".format(key, vals)) main() elif elapsed_time < 140: # 1020 # 0905 Delayed packages arrive # Truck 2 delivers delayed packages # with 1030 deadline first. # Truck 1 should arrive back to the hub @ 1007 truck_1 = t.load_truck(m, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) send_1(m, elapsed_time, distances_1, truck_1) start_time = elapsed_time - 65 truck_2 = t.load_truck(m, truck_2_packages) distances_2 = d.distance_traveled(elapsed_time, truck_2) send_2(m, start_time, distances_2, truck_2) print("\nPrinting Package Info for {}".format(inquiry_ID)) key, vals = m.retrieve(inquiry_ID) print("{}: {}".format(key, vals)) main() else: # wrong address is corrected # Truck 3 leaves after correction at 1020 truck_1 = t.load_truck(m, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) total_1 = send_1(m, elapsed_time, distances_1, truck_1) start_time = elapsed_time - 65 truck_2 = t.load_truck(m, truck_2_packages) distances_2 = d.distance_traveled(elapsed_time, truck_2) total_2 = send_2(m, start_time, distances_2, truck_2) start_time = elapsed_time - 140 new_address = "410 S State St" correct_address(m, truck_3_packages, new_address) truck_3 = t.load_truck(m, d, truck_3_packages) distances_3 = d.distance_traveled(elapsed_time, truck_3) total_3 = send_3(m, start_time, distances_3, truck_3) print("\nPrinting Package Info for {}".format(inquiry_ID)) key, vals = m.retrieve(inquiry_ID) print("{}: {}".format(key, vals)) main() elif choice == '2': # lookup package details address and time print("Preparing Simulation...") for packages in all_packages: m.retrieve(packages) print user_time = raw_input( "What time would you like to simulate? \n (24 hr format e.g. 0900, 1315): " ) if len(user_time) != 4 or ":" in user_time: # raise error message if time entered is not in a useable format raise ValueError( "Entry: {} is not a valid entry.\n\tPlease ensure the time you enter is in the format '0000'. E.g. 0900.\n\tDo not include ':' or 'AM' or 'PM'." .format(user_time)) else: if user_time[-2:] > '59': # raise error message if time entered isn't a valid time raise ValueError( 'Entry: {} -- minutes > 59 is not a valid time entry.'. format(user_time)) else: inquiry_address = raw_input("Enter Address: ") elapsed_time = convert_time(user_time) if elapsed_time < 65: # 0905 # 0800- all trucks get loaded # Truck 1, having the highest priority packages, # leaves first truck_1 = t.load_truck(m, d, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) send_1(m, elapsed_time, distances_1, truck_1) print("\nPrinting status for package(s) going to {}". format(inquiry_address)) packages = m.get_package_number(inquiry_address) print("{}\t{}\t{}".format(inquiry_address, packages, m.get_status(packages[0]))) main() elif elapsed_time < 140: # 1020 # 0905 Delayed packages arrive # Truck 2 delivers delayed packages # with 1030 deadline first. # Truck 1 should arrive back to the hub @ 1007 truck_1 = t.load_truck(m, d, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) send_1(m, elapsed_time, distances_1, truck_1) start_time = elapsed_time - 65 truck_2 = t.load_truck(m, d, truck_2_packages) distances_2 = d.distance_traveled(elapsed_time, truck_2) send_2(m, start_time, distances_2, truck_2) print("\nPrinting status for package(s) going to {}". format(inquiry_address)) packages = m.get_package_number(inquiry_address) print("{}\t{}\t{}".format(inquiry_address, packages, m.get_status(packages[0]))) main() else: # wrong address is corrected # Truck 3 leaves after correction at 1020 truck_1 = t.load_truck(m, d, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) total_1 = send_1(m, elapsed_time, distances_1, truck_1) start_time = elapsed_time - 65 truck_2 = t.load_truck(m, d, truck_2_packages) distances_2 = d.distance_traveled(elapsed_time, truck_2) total_2 = send_2(m, start_time, distances_2, truck_2) start_time = elapsed_time - 140 new_address = "410 S State St" correct_address(m, truck_3_packages, new_address) truck_3 = t.load_truck(m, d, truck_3_packages) distances_3 = d.distance_traveled(elapsed_time, truck_3) total_3 = send_3(m, start_time, distances_3, truck_3) print("\nPrinting status for package(s) going to {}". format(inquiry_address)) packages = m.get_package_number(inquiry_address) print("{}\t{}\t{}".format(inquiry_address, packages, m.get_status(packages[0]))) main() elif choice == '3': print("Preparing Simulation...") for packages in all_packages: m.retrieve(packages) print user_time = raw_input( "What time would you like to simulate? \n (24 hr format e.g. 0900, 1315): " ) if len(user_time) != 4 or ":" in user_time: # raise error message if time entered is not in a useable format raise ValueError( "Entry: {} is not a valid entry.\n\tPlease ensure the time you enter is in the format '0000'. E.g. 0900.\n\tDo not include ':' or 'AM' or 'PM'." .format(user_time)) else: if user_time[-2:] > '59': # raise error message if time entered isn't a valid time raise ValueError( 'Entry: {} -- minutes > 59 is not a valid time entry.'. format(user_time)) else: elapsed_time = convert_time(user_time) if elapsed_time < 65: # 0905 # 0800- all trucks get loaded # Truck 1, having the highest priority packages, # leaves first print( '\nloading truck 1...\ntruck 1 departed the hub at 0800\nstatus of packages on truck 1 as of {}...' .format(user_time)) truck_1 = t.load_truck(m, d, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) send_1(m, elapsed_time, distances_1, truck_1) print('\ntruck 2 is scheduled to leave the hub at 0905') print("truck 3 is scheduled to leave the hub at 1020") main() elif elapsed_time < 140: # 1020 # 0905 Delayed packages arrive # Truck 2 delivers delayed packages # with 1030 deadline first. # Truck 1 should arrive back to the hub @ 1007 print( '\nloading truck 1...\ntruck 1 departed the hub at 0800\nstatus of packages on truck 1 as of {}...' .format(user_time)) truck_1 = t.load_truck(m, d, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) send_1(m, elapsed_time, distances_1, truck_1) print( '\nloading truck 2...\ntruck 2 departed the hub at 0905\nstatus of packages on truck 2 as of {}...' .format(user_time)) start_time = elapsed_time - 65 truck_2 = t.load_truck(m, d, truck_2_packages) distances_2 = d.distance_traveled(elapsed_time, truck_2) send_2(m, start_time, distances_2, truck_2) print("\ntruck 3 is scheduled to leave the hub at 1020") main() else: # wrong address is corrected # Truck 3 leaves after correction at 1020 print( '\nloading truck 1...\ntruck 1 departed the hub at 0800\nstatus of packages on truck 1 as of {}...' .format(user_time)) truck_1 = t.load_truck(m, d, truck_1_packages) distances_1 = d.distance_traveled(elapsed_time, truck_1) total_1 = send_1(m, elapsed_time, distances_1, truck_1) print("total milage for truck 1: {}".format(total_1)) print( '\nloading truck 2...\ntruck 2 departed the hub at 0905\nstatus of packages on truck 2 as of {}...' .format(user_time)) start_time = elapsed_time - 65 truck_2 = t.load_truck(m, d, truck_2_packages) distances_2 = d.distance_traveled(elapsed_time, truck_2) total_2 = send_2(m, start_time, distances_2, truck_2) print("total milage for truck 2: {}".format(total_2)) print( '\nloading truck 3...\ntruck 3 departed the hub at 1020\nstatus of packages on truck 3 as of {}...' .format(user_time)) start_time = elapsed_time - 140 new_address = "410 S State St" correct_address(m, truck_3_packages, new_address) truck_3 = t.load_truck(m, d, truck_3_packages) distances_3 = d.distance_traveled(elapsed_time, truck_3) total_3 = send_3(m, start_time, distances_3, truck_3) print("total milage for truck 3: {}".format(total_3)) #print("\nPrinting Package Report as of {}...\n".format(user_time)) #m.print_all() truck_total = float(total_1) + float(total_2) + float( total_3) print("\nTotal distance traveled by all trucks: {:0.1f}". format(truck_total)) print("Last package is delivered at: 1229") main() elif choice == '4': print("Preparing Simulation...") for packages in all_packages: m.retrieve(packages) print user_time = raw_input( "What time would you like to simulate? \n (24 hr format e.g. 0900, 1315): " ) if len(user_time) != 4 or ":" in user_time: # raise error message if time entered is not in a useable format raise ValueError( "Entry: {} is not a valid entry.\n\tPlease ensure the time you enter is in the format '0000'. E.g. 0900.\n\tDo not include ':' or 'AM' or 'PM'." .format(user_time)) else: if user_time[-2:] > '59': # raise error message if time entered isn't a valid time raise ValueError( 'Entry: {} -- minutes > 59 is not a valid time entry.'. format(user_time)) else: elapsed_time = convert_time(user_time) if elapsed_time < 65: # 0905 # 0800- all trucks get loaded # Truck 1, having the highest priority packages, # leaves first print( '\nloading truck 1...\ntruck 1 has the following destinations' ) truck_1 = t.load_truck(m, truck_1_packages) print(truck_1) distances_1 = d.distance_traveled(elapsed_time, truck_1) send_1(m, elapsed_time, distances_1, truck_1) print("\nPrinting Status Report as of {}...\n".format( user_time)) m.print_all_status() main() elif elapsed_time < 140: # 1020 # 0905 Delayed packages arrive # Truck 2 delivers delayed packages # with 1030 deadline first. # Truck 1 should arrive back to the hub @ 1007 print( '\nloading truck 1...\ntruck 1 has the following destinations' ) truck_1 = t.load_truck(m, truck_1_packages) print(truck_1) distances_1 = d.distance_traveled(elapsed_time, truck_1) send_1(m, elapsed_time, distances_1, truck_1) print( '\nloading truck 2...\ntruck 2 has the following destinations' ) start_time = elapsed_time - 65 truck_2 = t.load_truck(m, truck_2_packages) print(truck_2) distances_2 = d.distance_traveled(elapsed_time, truck_2) send_2(m, start_time, distances_2, truck_2) print("\nPrinting Status Report as of {}...\n".format( user_time)) m.print_all_status() main() else: # wrong address is corrected # Truck 3 leaves after correction at 1020 print( '\nloading truck 1...\ntruck 1 has the following destinations' ) truck_1 = t.load_truck(m, truck_1_packages) print(truck_1) distances_1 = d.distance_traveled(elapsed_time, truck_1) total_1 = send_1(m, elapsed_time, distances_1, truck_1) print( '\nloading truck 2...\ntruck 2 has the following destinations' ) start_time = elapsed_time - 65 truck_2 = t.load_truck(m, truck_2_packages) print(truck_2) distances_2 = d.distance_traveled(elapsed_time, truck_2) total_2 = send_2(m, start_time, distances_2, truck_2) print( '\nloading truck 3...\ntruck 3 has the following destinations' ) start_time = elapsed_time - 140 new_address = "410 S State St" correct_address(m, truck_3_packages, new_address) truck_3 = t.load_truck(m, d, truck_3_packages) print(truck_3) distances_3 = d.distance_traveled(elapsed_time, truck_3) total_3 = send_3(m, start_time, distances_3, truck_3) print("\nPrinting Status Report as of {}...\n".format( user_time)) m.print_all_status() print("\nDay ends at: 1312") print("Total distance traveled by all trucks at 1312: {}". format( float(total_1) + float(total_2) + float(total_3))) main() else: print("\n======= Invalid Selection. Please try again. ========") print(" ================= select [1-3] =================\n") main()
print("Address: {0}".format(restaurant[4])) print("\n-------------\n") # gets a valid response to a yes or no question def get_valid_response(): response = input().lower() while response not in ('y','n'): print('Please enter\'y\' or \'n\'') response = input().lower() return response #Inserting food types into a data structure type_map = HashMap(30) for cuisine in types: # value_list is a list of all cuisines starting with the same letter value_list = type_map.retrieve(cuisine[0]) if value_list is None: # def: assign(self, key, value) type_map.assign(cuisine[0],[cuisine]) else: value_list += [cuisine] type_map.assign(cuisine[0],value_list) #Inserting restaurant data into a data structure restaurant_map = HashMap(100) for restaurant in restaurant_data: # cuisine type as key and restaurant name as value restaurant_type = restaurant[0] # restaurant_list is a list of restaurants with the same cuisine (I.E. Korean) restaurant_list = restaurant_map.retrieve(restaurant_type)
print("Invalid input: %s. Try again." % yes_or_no) # Utilizing a Stack to upload the restaurant list of lists in one go so that we don't # have to iterate over it more than once which keeps us at O(N) asyptotic notation. # The Stack module was not available in the project directory, so I had to create it # from the lesson. I also added a "fill" class var that initializes the Stack from a list arg. restack = Stack(fill=restaurant_data) food_type_hashmap = HashMap(30) restaurant_hashmap = HashMap(30) # Unpack the stack types.sort() while not restack.is_empty(): rest = restack.pop() # If the food_type hasn't been hashmap'd for a single char to a LinkedList, assign it, else insert. if not food_type_hashmap.retrieve(rest[0][0]): ll_char = LinkedList(rest[0]) food_type_hashmap.assign(rest[0][0], ll_char) else: fth_list = food_type_hashmap.retrieve(rest[0][0]) if not fth_list.exists(rest[0]): fth_list.insert_beginning(rest[0]) # If the food_type hasn't been hashmap'd for a two char to a LinkedList, assign it. # Future work: If we need to go beyond 2 chars, we'll insert here, and then grab a third. if not food_type_hashmap.retrieve(rest[0][:2]): ll_char2 = LinkedList(rest[0]) food_type_hashmap.assign(rest[0][:2], ll_char2) # Create the food type hashmap of LinkedListed restaurants. if not restaurant_hashmap.retrieve(rest[0]): ll_rest = LinkedList(rest)
return to_return #Printing the Welcome Message print_welcome() #Write code to insert food types into a data structure here. The data is in data.py # gather all first letters for food types first_letters = [food_type[:1] for food_type in types] # initialize hash map to map first letters to linked list of food types letter_food_map = HashMap(len(first_letters)) # map first letter of food types to a linked list of food types for food_type in types: if letter_food_map.retrieve(food_type[:1]) is None: letter_food_map.assign(food_type[:1], LinkedList(food_type)) else: old_linked_list = letter_food_map.retrieve(food_type[:1]) old_linked_list.insert_beginning(food_type) letter_food_map.assign(food_type[:1], old_linked_list) ## TEST CASE ## #print(letter_food_map.retrieve('c').stringify_list()) #Write code to insert restaurant data into a data structure here. The data is in data.py # will map food type to a linked list of restaurants with given type type_restaurant_map = HashMap(len(types)) for restaurant in restaurant_data:
#Write code to insert restaurant data into a data structure here. The data is in data.py hashmap = HashMap(len(types)) for food_type in types: linkedlist = LinkedList() for restaurant in restaurant_data: if food_type == restaurant[0]: linkedlist.insert_beginning(restaurant) hashmap.assign(food_type, linkedlist) #Write code for user interaction here while True: user_input = str(input("\nSearch for a food type here. \nType 'quit' anytime to exit.\n")).lower() if user_input == 'quit': exit() #Search for user_input in food types data structure here if len(trie.find_words(user_input)) < 1: print('No food types found. Try again') else: if len(trie.find_words(user_input)) > 1: print("Your choices are: {}".format(trie.find_words(user_input))) else: user_input_select = str(input("\nThe closest search result is: {}\n Would you like to look at this type? \n 'y' for yes or 'n' for no.\nType 'quit' to exit.\n".format(trie.find_words(user_input)[0]))).lower() if user_input_select == 'y': ll = hashmap.retrieve(trie.find_words(user_input)[0]) head_node = ll.get_head_node() while head_node.value != None: print("\n Name: {0} \n Price: {1} \n Rating: {2} \n Address: {3} \n".format(head_node.value[1], head_node.value[2], head_node.value[3], head_node.value[4])) head_node = head_node.get_next_node() elif user_input_select == 'quit': exit()
else: current_node = current_node.get_next_node() if len(matches) == 0: print("\nNo food types match your search.") elif len(matches) == 1: yn = str( input( "\nThe only option with those beginning letters is {0}. Do you to look at {0} restaurants? Enter 'y' for yes and 'n' for no." .format(matches[0]))) if yn == 'y': #After finding food type write code for retrieving restaurant data here user_type = matches[0] print("\nDisplaying {0} restaurants...".format(user_type)) rest_list = type_rest.retrieve(user_type) current_rest_node = rest_list.get_head_node() while current_rest_node: current_rest = current_rest_node.get_value() if current_rest is not None: print("-------------") print("Name: {0}".format(current_rest.retrieve("name"))) print("Prince: {0}".format(current_rest.retrieve("price"))) print("Rating: {0}".format( current_rest.retrieve("rating"))) print("Address: {0}".format( current_rest.retrieve("address"))) current_rest_node = current_rest_node.get_next_node() elif yn == 'n': print("\nOk, let's try again")
ll = LinkedList() for j in restaurant_data: if j[0] == i and ll.head_node.get_value(): nt = Restaurant(j[0], j[1], j[2], j[3], j[4]) ll.insert_beginning(nt) elif j[0] == i and not ll.head_node.get_value(): nt = Restaurant(j[0], j[1], j[2], j[3], j[4]) ll = LinkedList(nt) type_to_data_hashmap.assign(i, ll) #Write code for user interaction here while True: #Search for user_input in food types data structure here restaurant = handle_user_input(letter_to_type_hashmap) print("You chose {0}".format(restaurant.title())) choice = type_to_data_hashmap.retrieve(restaurant) pretty_print(choice) answer = input("Continue searching for more restaurants? [y/n]\n") if answer.lower() == 'y': continue elif answer.lower() == 'n': print("See ya!") sys.exit() else: print("{0} is not a valid choice".format(answer)) continue
input( 'The following options are available: {0}! Please write out a little more to pick one.\n' .format(choices))) elif length == 1: input2 = str( input( 'The only option beginning with {0} is {1}. Do you want to look at {1} restaurants? Enter \'y\' for yes and \'n\' for no.\n' .format(user_input, choice))) if input2 == 'n': print('Ok! Let\'s try again.') continue #After finding food type write code for retrieving restaurant data here if input2 == 'y': print( 'Here are all the {0} restaurants in SoHo!'.format(choice)) resto = resto_styles.retrieve(choice).get_head_node() while resto.get_next_node() != None: print( '\nName: {0}\nPrice: {1}\nRating: {2}\nAddress: {3}\n'. format(resto.get_value().retrieve('Name'), resto.get_value().retrieve('Price'), resto.get_value().retrieve('Rating'), resto.get_value().retrieve('Address'))) resto = resto.get_next_node() input3 = (str( input( 'Do you want to look at other restaurants? Enter \'y\' for yes and \'n\' for no.\n' ))) if input3 == 'y': continue elif input3 == 'n':
from linkedlist import LinkedList #Printing the Welcome Message print_welcome() #Write code to insert food types into a data structure here. The data is in data.py food_types = Trie() food_types.make_trie(types) #Write code to insert restaurant data into a data structure here. The data is in data.py restaurants = HashMap(len(types)) for restaurant_datum in restaurant_data: key, value = restaurant_datum[0], restaurant_datum[1:] if not restaurants.has_key(key): restaurants.assign(key, LinkedList(value)) else: restaurants.retrieve(key).insert_beginning(value) #Write code for user interaction here while True: #start the loop by clearing any suggested words food_types.reset_words() user_input = str( input( "\nWhat type of food would you like to eat?\nType the beginning of that food type and press enter to see if it's here, or press 'Enter' with no input to see all options.\n" )).lower() #Search for user_input in food types data structure here res = food_types.return_suggestions(user_input) if res == -1: print("No other strings found with this prefix\n") elif res == 0: print("No string found with this prefix\n") else:
if not valid_input: print("\nNo results found. Please try again...") while len(valid_input) > 1: print("\nMultiple results found:") for restaurant_type in valid_input: print(restaurant_type) user_input2 = str(input("\nPlease enter more letters.\n")).lower() valid_input = types_trie.return_possibilities(user_input2) print("\nSingle result found:") print(valid_input[0]) # After finding food type write code for retrieving restaurant data here if proceed(): print("\nDisplaying restaurant information...") selected_restaurants = restaurants_hash.retrieve(valid_input[0]) node = selected_restaurants.get_head_node() while node: rest = node.get_value() print("\n******************************") print("Name: " + rest.retrieve("name")) print("Price: " + rest.retrieve("price")) print("Rating: " + rest.retrieve("rating")) print("Address: " + rest.retrieve("address")) node = node.get_next_node() user_input4 = str(input("\nSearch again? Enter y or n.\n")).lower() if user_input4 == 'y': pass elif user_input4 == 'n': break