def loopDetection(linkedList): myHashTable = HashTable() current = linkedList.head while (current.next): if (myHashTable.get(current)): return current else: myHashTable.put(current, current.value) current = current.next
def main(): t = HashTable() buildFromFile(t, 'small.dict') #t.keys() ans = t.search(input("enter word to search for: "), 1) if (ans == True): print("valid word") else: print("invalid word")
def removeDups(linkedList): myHashTable = HashTable() current = linkedList.head while (current): myHashTable.put(current.value, "node") current = current.next entries = myHashTable.getEntries() current = linkedList.head for i in range(0, len(entries)): if (i == 0): linkedList.head.value = entries[i]['key'] else: current.next.value = entries[i]['key'] current = current.next current.next = None return linkedList
class SymbolTable: def __init__(self): self.symTable = HashTable(40) def getSymTable(self): return self.symTable def getHashAtIndex(self, index): return self.symTable.hashTable[index] def addSymbol(self, key): position = self.symTable.add(key) return position def getTokenPosition(self, token): return self.symTable.getPosition(token)
def main(): table = HashTable() buildFromFile(table, 'ispell.dict') print("dictionary built.") while True: word = input("word: ") if (table.search(word, 1) == True): print("Word found") else: list = getWordList(word) print("Suggestions: ", end="") for w in list: if (table.search(w, 1) == True): print(w, end=" ") print("\n")
def linkedListPalindrome(linkedList): myHashTable = HashTable() pointer = linkedList.head while (pointer): if (myHashTable.get(pointer.value)): myHashTable.put(pointer.value, myHashTable.get(pointer.value) + 1) else: myHashTable.put(pointer.value, 1) pointer = pointer.next isPalindrome = True evenCount = 0 oddCount = 0 for i in range(0, len(myHashTable.getEntries())): if (myHashTable.getEntries()[i]['value'] % 2 == 0): evenCount = evenCount + 1 else: oddCount = oddCount + 1 if (oddCount > 1): isPalindrome = False return isPalindrome
def zeroMatrix(matrix): m = len(matrix) n = len(matrix[0]) iHashTable = HashTable() jHashTable = HashTable() for i in range(0, m): for j in range(0, n): if (matrix[i][j] == 0): iHashTable.put(i, "i") jHashTable.put(j, "j") ientries = iHashTable.getEntries() jentries = jHashTable.getEntries() for i in range(0, len(ientries)): for j in range(0, n): matrix[ientries[i]['key']][j] = 0 for i in range(0, len(jentries)): for j in range(0, m): matrix[j][jentries[i]['key']] = 0 return matrix
def main(): table = HashTable(30) choice = int( input( "Choose dictionary to use:\n1. small.dict\n2. ispell.dict\n9. Exit\n" )) if choice == 1: f = open("small.dict", "r") elif choice == 2: f = open("ispell.dict", "r") elif choice == 9: return 0 a = f.read().splitlines() print("Loading dictionary. Please wait...\n") for word in a: table.insert(word) print("Ready! Please enter values...") while True: key = input("Enter element to search: (Enter k to exit)\n") if key == 'k': break else: table.search(key)
def palindromePermutation(string): word = string.lower() myHashTable = HashTable() for i in range(0, len(word)): if (myHashTable.get(word[i]) != None): myHashTable.put(word[i], myHashTable.get(word[i]) + 1) elif (myHashTable.get(word[i]) == None and word[i] != " "): myHashTable.put(word[i], 1) numOfEvenOccurences = 0 numOfOddOccurences = 0 entries = myHashTable.getEntries() for i in range(0, len(entries)): if (entries[i]['value'] % 2 == 0): numOfEvenOccurences = numOfEvenOccurences + 1 elif (entries[i]['value'] % 2 == 1): numOfOddOccurences = numOfOddOccurences + 1 if (numOfOddOccurences > 1): return False else: return True
class SymbolTable: def __init__(self): self.symTableIdentifiers = HashTable(17) self.symTableConstants = HashTable(17) def getIdentifiers(self): return self.symTableIdentifiers def getConstants(self): return self.symTableConstants def addIdentifier(self, key): position = self.symTableIdentifiers.add(key) return position def addConstant(self, key): position = self.symTableConstants.add(key) return position def getPositionIdentifier(self, token): return self.symTableIdentifiers.getPosition(token) def getPositionConstant(self, token): return self.symTableConstants.getPosition(token)
from hashTable import HashTable from truck import Truck from distance_data import DistanceData import utility printMenu.print_menu() menu = True while menu: # truck1 start time delta_1 = timedelta(hours=8) # truck2 start time delta_2 = timedelta(hours=9, minutes=5) # truck3 start time delta_3 = timedelta(hours=10, minutes=20) # Create the hash table object hash_table = HashTable() # load the hash table HashTable.load_table(hash_table) # create and load the distance graph distance_graph = DistanceData.load_graph() # instantiate truck1 truck1 = Truck(distance_graph, hash_table, delta_1) # instantiate truck2 truck2 = Truck(distance_graph, hash_table, delta_2) # instantiate truck3 truck3 = Truck(distance_graph, hash_table, delta_3) # load packages on truck1 truck1.load_packages("4", "7", "13", "14", "15", "16", "19", "20", "27", "29", "34", "40", "23", "11", "17") # make a sub-graph of the package locations truck1.create_sub_graph()
from hashTable import HashTable H = HashTable() H[20] = 13 H[21] = 14 H[31] = 20 H[31] = 21 print(H[20]) print(H[21]) print(H[31]) print(len(H)) print(31 in H) H.describe()
def alphaBeta(board, player, ply, depth): """ Alpha-Beta pruning algorithm. :param board: the board that minimax is performed on; :param player: the player whose turn it is; :param ply: the turn number :param - alpha: alpha value :param - beta: beta value :return value: value of the game. """ rec_table = HashTable() node_count = 0 table_hits = 0 def do_alphaBeta(board, player, ply, alpha, beta, depth): """ For memoization. """ nonlocal node_count nonlocal table_hits # update stats node_count += 1 # Transposition: board_hash = board.encode() if USE_TRANSPOSITION and board_hash in rec_table and\ depth <= rec_table[board_hash][1]: table_hits += 1 return rec_table[board_hash][0] # evaluate board b_eval = Evaluate(board) if b_eval.utility(ply) != Constants.NON_TERMINAL: # terminal node ret = b_eval.utility(ply) elif depth <= 0: ret = b_eval.evaluation() else: successors = board.successors(player) if len(successors) <= 0: ret = Constants.DRAW elif player == Constants.MAX: v = Constants.NEGINF for child in successors: v = max(v, do_alphaBeta(child, Constants.MIN, ply+1, \ alpha, beta, depth-1)) alpha = max(alpha, v) if beta <= alpha: break # beta cut-off ret = v else: v = Constants.INF for child in successors: v = min(v, do_alphaBeta(child, Constants.MAX, ply+1, \ alpha, beta, depth-1)) beta = min(beta, v) if beta <= alpha: break # alpha cut-off ret = v # Transposition: if USE_TRANSPOSITION: rec_table[board_hash] = (ret, depth) return ret return do_alphaBeta(board, player, ply, \ Constants.NEGINF, \ Constants.INF, depth), \ len(rec_table), \ node_count, table_hits
def minimax(board, player, ply, depth): """ Minimax algorithm. :param board: the board that minimax is performed on; :param player: the player whose turn it is; :param ply: the turn number; :return value: value of the game. """ rec_table = HashTable() node_count = 0 table_hits = 0 ### Internal function begins def do_minimax(board, player, ply, depth): """ For memoization. """ # Stats: nonlocal node_count nonlocal table_hits node_count += 1 # Transposition: board_hash = board.encode() if USE_TRANSPOSITION and board_hash in rec_table and\ depth <= rec_table[board_hash][1]: table_hits += 1 return rec_table[board_hash][0] # evaluate board b_eval = Evaluate(board) if b_eval.utility(ply) != Constants.NON_TERMINAL: # End game ret = b_eval.utility(ply) elif depth <= 0: # max search depth hit ret = b_eval.evaluation() else: # recursive case successors = board.successors(player) # No successors is a draw if len(successors) <= 0: ret = Constants.DRAW elif player == Constants.MAX: best_value = Constants.NEGINF for succ in successors: v = do_minimax(succ, Constants.MIN, ply + 1, depth - 1) best_value = max(best_value, v) ret = best_value else: # if player is minimizer best_value = Constants.INF for succ in successors: v = do_minimax(succ, Constants.MAX, ply + 1, depth - 1) best_value = min(best_value, v) ret = best_value # Transposition: if USE_TRANSPOSITION: rec_table[board_hash] = (ret, depth) return ret ### Internal function ends return do_minimax(board, player, ply, depth), \ len(rec_table), \ node_count, table_hits
from hashTable import HashTable tab = HashTable() tab["Hello"] = "Hello1" tab["Hello"] = "Hello2" tab["World"] = "World" print(tab["Hello"]) print(tab["World"]) print("\n\nKey-Value Pairs:") for k,v in tab.items(): print(k,v) print("\n\nKeys:") for i in tab.keys(): print(i) print("\n\nValues:") for i in tab: print(i)
def __init__(self): self.symTableIdentifiers = HashTable(17) self.symTableConstants = HashTable(17)
def test_init(self): ht = HashTable(4) assert len(ht.buckets) == 4 assert ht.length() == 0
from dynamicArray import DynamicArray from FileIo import FileIo from hashTable import HashTable print("Hashing Function 2") arr = DynamicArray() F = FileIo(filename="Customer.csv") table = HashTable(table=arr) F.file_io_chaining2(table) j = 0 print("%4s" % "No.", end=" ") print("%17s" % "Customer Id", end=" ") print("%14s" % "First Name", end=" ") print("%9s" % "Last Name") for i in range(len(table.table.array)): if table.table.array[i] is None: j += 1 if table.table.array[i] is not None: linkedlist = table.get_hashed(i) a = "[" + str(linkedlist.key) + "]" print("%4s" % a, end=" ") print("%17s" % linkedlist.head.data.customer_id, end=" ") print("%14s" % linkedlist.head.data.first_name, end=" ") print("%9s" % linkedlist.head.data.last_name, end=" ") if table.table.array[i].GetLength() > 1: start = linkedlist.head.next while start is not None: print("%17s" % start.data.customer_id, end=" ") print("%14s" % start.data.first_name, end=" ") print("%9s" % start.data.last_name, end=" ") start = start.next
from tkinter import * from tkinter import ttk import csv import package from distance import Distances from hashTable import HashTable from truck import Trucks import datetime from datetime import datetime with open('WGUPSPackageFile1.csv', 'r') as csvfile: csv_file = csv.reader(csvfile, delimiter=',') # reads the CSV package file list_of_packages = list(csv_file) # print(list_of_packages[0][0]) pH = HashTable( ) # 15 - creates a hashtable object by calling the HashTable class distances = Distances() trucks = Trucks() # creates truck object by calling Trucks class # creates lists of each package attribute Package_IDs = [] Addresses = [] Cities = [] States = [] Zips = [] Delivery_Deadlines = [] Weight = [] Notes = [] Status = []
def test_hash_fun(self): hashTable = HashTable(19, 3) self.assertEqual(hashTable.hash_fun('fsdfhxvn980cvnxcbfvjksd'), 8) self.assertEqual(hashTable.hash_fun('fsdfhxvnxmcvnxcbfvjksd'), 9) self.assertEqual(hashTable.hash_fun('yery54n77ji'), 8) self.assertEqual(hashTable.hash_fun('ert43564645'), 5) self.assertEqual(hashTable.hash_fun('rtbktut'), 16) self.assertEqual(hashTable.hash_fun('ывспмкенкнк'), 11) self.assertEqual(hashTable.hash_fun('fsdfhxvnxmcv08905xcbfvjksd'), 8) self.assertEqual(hashTable.hash_fun('вкс3еме45н5 564 '), 18) self.assertEqual(hashTable.hash_fun('fsdfhxыапукetxmcvnxcbfvjksd'), 6) self.assertEqual(hashTable.hash_fun('fsdfhxvnxmcvnxc5435sd'), 13) self.assertEqual(hashTable.hash_fun('fsdfhxvnxm5443nxcbfvjksd'), 13)
def test_find(self): hashTable = HashTable(19, 3) self.assertEqual(hashTable.put('fsdfhxvn980cvnxcbfvjksd'), 8) self.assertEqual(hashTable.put('fsdfhxvnxmcvnxcbfvjksd'), 9) self.assertEqual(hashTable.put('yery54n77ji'), 11) self.assertEqual(hashTable.put('ert43564645'), 5) self.assertEqual(hashTable.put('rtbktut'), 16) self.assertEqual(hashTable.put('ывспмкенкнк'), 14) self.assertEqual(hashTable.put('fsdfhxvnxmcv08905xcbfvjksd'), 17) self.assertEqual(hashTable.put('вкс3еме45н5 564 '), 18) self.assertEqual(hashTable.put('fsdfhxыапукetxmcvnxcbfvjksd'), 6) self.assertEqual(hashTable.put('fsdfhxvnxmcvnxc5435sd'), 13) #self.assertEqual(hashTable.put('fsdfhxvnxm5443nxcbfvjksd'), 0) # print('test_find') self.assertEqual(hashTable.find('fsdfhxvnxmcv08905xcbfvjksd'), 17) self.assertEqual(hashTable.find('fsdfhxvnxmcvnxcbfvjksd'), 9) self.assertEqual(hashTable.find('yery54n77ji'), 11) self.assertEqual(hashTable.find('ert43564645'), 5) self.assertEqual(hashTable.find('fsdfhxvn980cvnxcbfvjksd'), 8) self.assertEqual(hashTable.find('fsdfhxvnxmcvnxc5435sd'), 13) self.assertEqual(hashTable.find('ывспмкенкнк'), 14) self.assertEqual(hashTable.find('вкс3еме45н5 564 '), 18) self.assertEqual(hashTable.find('fsdfhxыапукetxmcvnxcbfvjksd'), 6) self.assertEqual(hashTable.find('rtbktut'), 16) self.assertEqual(hashTable.find('fsdfhxvnxm5443nxcbfvjksd'), None)
def test_put_anomale(self): hashTable = HashTable(1, 1) self.assertEqual(hashTable.put('fsdfhxvn980cvnxcbfvjksd'), 0) self.assertEqual(hashTable.put('fsdfhxvnxmcvnxcbfvjksd'), None) hashTable = HashTable(-1, 1) with self.assertRaises(ValueError): self.assertEqual(hashTable.put('fsdfhxvnxmcvnxcbfvjksd'), None) hashTable = HashTable(1, -10) self.assertEqual(hashTable.put('fsdfhxvn980cvnxcbfvjksd'), 0) self.assertEqual(hashTable.put('fsdfhxvnxmcvnxcbfvjksd'), None) hashTable = HashTable(1, 3) self.assertEqual(hashTable.put(''), 0) self.assertEqual(hashTable.put(''), None) self.assertEqual(hashTable.put(''), None)
start = datetime.datetime.now() ht = HT() for num in nums: if ht.contains(num): ht.set(num, ht.get(num) + 1) else: ht.add(num, 1) for num in set(nums): print(ht.get(num)) end = datetime.datetime.now() print(end - start) start = datetime.datetime.now() ht = HashTable() for num in nums: if ht.contains(num): ht.set(num, ht.get(num) + 1) else: ht.add(num, 1) for num in set(nums): print(ht.get(num)) end = datetime.datetime.now() print(end - start) start = datetime.datetime.now() avl = AVLMap() for num in nums: if avl.contains(num):
i = 0 noise = re.search('[^ATCG]', entry[0:25]) while noise != None and i < len(entry) - 24: i = noise.span()[1] noise = re.search('[^ATCG]', entry[i:i + 25]) return i def evaluateLine(line, entry): if line.startswith('>'): count25mers(entry) return '' else: return entry + line.replace('\n', '') try: hashtable = HashTable() filename = sys.argv[1] file = open(filename) entry = '' for line in file: entry = evaluateLine(line, entry) file.close() count25mers(entry) except Exception as e: print(e) finally: print('Distinct 25-mers: ' + str(hashtable.size)) print('Total 25-mers: ' + str(hashtable.total)) print('Highest count: ' + hashtable.mostCommon)
def main_one(): with open('WGUPSPackageFile1.csv', 'r') as csvfile: csv_file = csv.reader(csvfile, delimiter=',') # reads the CSV package file list_of_packages = list(csv_file) # print(list_of_packages[0][0]) packageHashTable = HashTable() # 15 - creates a hashtable object by calling the HashTable class distances = Distances() trucks = Trucks() # creates truck object by calling Trucks class # creates lists of each package attribute Package_IDs = [] Addresses = [] Cities = [] States = [] Zips = [] Delivery_Deadlines = [] Weight = [] Notes = [] Status = [] Departure_time = [] # reads the package csv and creates attributes for each package for row in list_of_packages: # space time complexity is O(N) pid = row[0].strip() address = row[1] city = row[2] state = row[3] zipcode = row[4] deadline = row[5] weight = row[6] note = row[7] status = row[8] departure_time = row[9] # appends each value to respective lists Package_IDs.append(pid) Addresses.append(address) Cities.append(city) States.append(state) Zips.append(zipcode) Delivery_Deadlines.append(deadline) Weight.append(weight) Notes.append(note) Status.append(status) Departure_time.append(departure_time) p = package.Package(pid, address, city, state, zipcode, deadline, weight, note) # creates the package object using the package class packageHashTable.get(pid) # look up the package by the id packageHashTable.insert(pid, p) # inserts the packages into the hashtable # gets the package object using the ids using the hashtable and creates package objects for each p1 = packageHashTable.get('1') p5 = packageHashTable.get('5') p7 = packageHashTable.get('7') p8 = packageHashTable.get('8') p10 = packageHashTable.get('10') p11 = packageHashTable.get('11') p12 = packageHashTable.get('12') p13 = packageHashTable.get('13') p14 = packageHashTable.get('14') p15 = packageHashTable.get('15') p16 = packageHashTable.get('16') p19 = packageHashTable.get('19') p20 = packageHashTable.get('20') p29 = packageHashTable.get('29') p30 = packageHashTable.get('30') p34 = packageHashTable.get('34') p37 = packageHashTable.get('37') p3 = packageHashTable.get('3') p6 = packageHashTable.get('6') p18 = packageHashTable.get('18') p25 = packageHashTable.get('25') p26 = packageHashTable.get('26') p31 = packageHashTable.get('31') p36 = packageHashTable.get('36') p38 = packageHashTable.get('38') p40 = packageHashTable.get('40') p2 = packageHashTable.get('2') p4 = packageHashTable.get('4') p9 = packageHashTable.get('9') p17 = packageHashTable.get('17') p21 = packageHashTable.get('21') p22 = packageHashTable.get('22') p23 = packageHashTable.get('23') p24 = packageHashTable.get('24') p27 = packageHashTable.get('27') p28 = packageHashTable.get('28') p32 = packageHashTable.get('32') p33 = packageHashTable.get('33') p35 = packageHashTable.get('35') p39 = packageHashTable.get('39') # p37.status = 'At Hub' # print(p37) firstTruckTripPackages = [p1, p7, p8, p10, p11, p12, p13, p14, p15, p16, p19, p20, p29, p30, p34, p37] # print(p1.pid) # puts the packages into the first truck # print(packageHashTable.update_status('1', 'At HUB')) firstTruckTripPAddresses = [] for item in firstTruckTripPackages: firstTruckTripPackageA = item.address firstTruckTripPAddresses.append(firstTruckTripPackageA) # creates a list of addresses of each package in the first truck # space time complexity of O(N) secondTruckTripPackages = [p3, p6, p18, p25, p26, p31, p36, p38, p40] # puts the package object into the second truck secondTruckTripPAddresses = [] for item in secondTruckTripPackages: secondTruckTripPackageA = item.address secondTruckTripPAddresses.append(secondTruckTripPackageA) # creates a list of addresses of each package in the second truck # space time complexity of O(N) thirdTruckTripPackages = [p2, p4, p5, p9, p17, p21, p22, p23, p24, p27, p28, p32, p33, p35, p39] # puts the package object into the third truck thirdTruckTripPAddresses = [] for item in thirdTruckTripPackages: firstTruckSecondTripPackageA = item.address thirdTruckTripPAddresses.append(firstTruckSecondTripPackageA) # creates a list of addresses of each package in the second truck # space time complexity of O(N) first_location = 'HUB' # creates list of addresses from the optimized list of addresses from truck 1 first_truck_delivery = trucks.shortest_distance_calculation_truck1_addresses( firstTruckTripPAddresses, firstTruckTripPackages, first_location) # creates list of addresses from the optimized list of addresses from truck 2 second_truck_delivery = trucks.shortest_distance_calculation_truck2_addresses( secondTruckTripPAddresses, secondTruckTripPackages, first_location) # creates list of addresses from the optimized list of addresses from truck 3 third_truck_delivery = trucks.shortest_distance_calculation_truck3_addresses( thirdTruckTripPAddresses, thirdTruckTripPackages, first_location) # lines 166-168 update each package departure time trucks.update_package_departure_from_hub_time_first_truck(firstTruckTripPackages) trucks.update_package_departure_from_hub_time_second_truck(secondTruckTripPackages) trucks.update_package_departure_from_hub_time_third_truck(thirdTruckTripPackages) # lines 167-169 update each package delivery time to the time they are delivered trucks.update_package_delivery_time_first_truck(first_truck_delivery, firstTruckTripPackages, 'HUB') trucks.update_package_delivery_time_second_truck(second_truck_delivery, secondTruckTripPackages, 'HUB') trucks.update_package_delivery_time_third_truck(third_truck_delivery, thirdTruckTripPackages, 'HUB') # for item in firstTruckTripPackages: # print(item.pid) # print(item.departure_time) # print(item.delivery_time) # print('\n') # # # for item2 in secondTruckTripPackages: # print(item2.pid) # print(item2.departure_time) # print(item2.delivery_time) # print('\n') # # for item3 in thirdTruckTripPackages: # print(item3.pid) # print(item3.departure_time) # print(item3.delivery_time) # print('\n') print('Hello, welcome to the portal of the Western Governors University Parcel Service!') print('Below is the total miles traveled in by each truck delivery:') first_truck_miles = trucks.calculate_total_distance_traveled_per_truck(first_truck_delivery, 'HUB') print('First truck miles: ', first_truck_miles) second_truck_miles = trucks.calculate_total_distance_traveled_per_truck(second_truck_delivery, 'HUB') print('Second truck miles: ', second_truck_miles) third_truck_miles = trucks.calculate_total_distance_traveled_per_truck(third_truck_delivery, 'HUB') print('Third truck miles: ', third_truck_miles) print('Total miles: ', first_truck_miles + second_truck_miles + third_truck_miles) first_input = input("Please enter 'get' or 'status' to get started. 'Get' will return package information and " "'status' will return status information for a certain time: ") # space time complexity O(N^2) while first_input is not 'exit': if first_input == 'get': p = input("Please enter package ID: ") for package_id_input in firstTruckTripPackages: # gets package information from each package in truck 1 if package_id_input.pid == p: departure_time = package_id_input.departure_time delivery_time = package_id_input.delivery_time user_input_time = input("please enter a time in the 'HH:MM:SS' format: ") convert_user_input_time = datetime.strptime(user_input_time, '%H:%M:%S') if departure_time >= convert_user_input_time: # checks if package is at hub and then sets # value in hashtable package_id_input.status = 'At HUB' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) elif departure_time <= convert_user_input_time: # checks if package is in transit # then sets in hashtable if convert_user_input_time < delivery_time: package_id_input.status = 'In transit' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) else: # checks if package is delivered and then sets value in hashtable package_id_input.status = 'Delivered' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) for package_id_input in secondTruckTripPackages: # gets package information from each package in truck 2 if package_id_input.pid == p: departure_time = package_id_input.departure_time delivery_time = package_id_input.delivery_time user_input_time = input("please enter a time in the 'HH:MM:SS' format: ") convert_user_input_time = datetime.strptime(user_input_time, '%H:%M:%S') if departure_time >= convert_user_input_time: package_id_input.status = 'At HUB' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) elif departure_time <= convert_user_input_time: if convert_user_input_time < delivery_time: package_id_input.status = 'In transit' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) else: package_id_input.status = 'Delivered' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) for package_id_input in thirdTruckTripPackages: # gets package information from each package in truck 3 if package_id_input.pid == p: departure_time = package_id_input.departure_time delivery_time = package_id_input.delivery_time user_input_time = input("please enter a time in the 'HH:MM:SS' format: ") convert_user_input_time = datetime.strptime(user_input_time, '%H:%M:%S') if departure_time >= convert_user_input_time: # checks if package is at the hub package_id_input.status = 'At HUB' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) elif departure_time <= convert_user_input_time: # checks if package is in transit or delivered if convert_user_input_time < delivery_time: package_id_input.status = 'In transit' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) else: package_id_input.status = 'Delivered' print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ', package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ', package_id_input.zip_code, 'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ', package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ', package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time) # checks the status of each package in all three trucks elif first_input == 'status': user_input_input_time = input("Please enter starting time in 'HH:MM:SS' format: ") convert_user_input_time = datetime.strptime(user_input_input_time, '%H:%M:%S') # converts time inputted to datetime for p in firstTruckTripPackages: # checks status of the first truck departure_time = p.departure_time delivery_time = p.delivery_time if departure_time >= convert_user_input_time: # checks if package is at the HUB p.status = 'At HUB' print('Package ID: ', p.pid, 'Status: ', p.status) elif delivery_time <= convert_user_input_time: # checks if package has been delivered p.status = 'Delivered' print('Package ID: ', p.pid, 'Status: ', p.status) elif departure_time <= convert_user_input_time < delivery_time: # checks if package is in transit p.status = 'In transit' print('Package ID: ', p.pid, 'Status: ', p.status) for p in secondTruckTripPackages: # checks status of the second truck departure_time = p.departure_time delivery_time = p.delivery_time if departure_time >= convert_user_input_time: # checks if package is at the hub p.status = 'At HUB' print('Package ID: ', p.pid, 'Status: ', p.status) elif delivery_time <= convert_user_input_time: # checks if package has been delivered p.status = 'Delivered' print('Package ID: ', p.pid, 'Status: ', p.status) elif departure_time <= convert_user_input_time < delivery_time: # checks if package is in transit p.status = 'In transit' print('Package ID: ', p.pid, 'Status: ', p.status) for p in thirdTruckTripPackages: # checks status of third truck departure_time = p.departure_time delivery_time = p.delivery_time if departure_time >= convert_user_input_time: # checks if package is at the hub p.status = 'At HUB' print('Package ID: ', p.pid, 'Status: ', p.status) elif delivery_time <= convert_user_input_time: # checks if package has been delivered p.status = 'Delivered' print('Package ID: ', p.pid, 'Status: ', p.status) elif departure_time <= convert_user_input_time < delivery_time: # checks if package is in transit p.status = 'In transit' print('Package ID: ', p.pid, 'Status: ', p.status) elif first_input == 'exit': exit()
def test_length(self): ht = HashTable() assert ht.length() == 0 ht.set('I', 1) assert ht.length() == 1 ht.set('V', 5) assert ht.length() == 2 ht.set('X', 10) assert ht.length() == 3
ages_ans_often_fem = [] ages_ans_some_fem = [] ages_ans_often_other = [] ages_ans_some_other = [] ages_ans_often_male = [] ages_ans_some_male = [] survey_answers_ages = [] survey_answers_ages_fem = [] survey_answers_ages_male = [] survey_answers_ages_other = [] with open('TechMentalHealthSurvey.csv', 'r') as csvfile: csv_file = csv.reader(csvfile, delimiter=',') # reads the CSV package file list_of_answers = list(csv_file) # print(list_of_packages[0][0]) mhsurvey = HashTable( ) # 15 - creates a hashtable object by calling the HashTable class Row_IDs = [] Age = [] Gender = [] Country = [] State = [] Self_employed = [] Family_history = [] Treatment = [] Work_interference = [] No_employees = [] Remote_work = [] Tech_company = [] Benefits = [] Care_options = []
def test_set_and_get(self): ht = HashTable() ht.set('I', 1) ht.set('V', 5) ht.set('X', 10) assert ht.get('I') == 1 assert ht.get('V') == 5 assert ht.get('X') == 10 assert ht.length() == 3 with self.assertRaises(KeyError): ht.get('A') # Key does not exist
def __init__(self): self.symTable = HashTable(40)
def test_delete(self): ht = HashTable() ht.set('I', 1) ht.set('V', 5) ht.set('X', 10) assert ht.length() == 3 ht.delete('I') ht.delete('X') assert ht.length() == 1 with self.assertRaises(KeyError): ht.delete('X') # Key no longer exists with self.assertRaises(KeyError): ht.delete('A') # Key does not exist