def multiplyHandler(a, b): key = (a,b) if key in CACHE: print CACHE[key] else: result = fake_database.russian(a, b) CACHE[key] = result lastFiveList.append('{}x{}={}'.format(a,b,result)) print 'Latest Result: {}'.format(result)
def multiplyHandler(a, b): """ Write this function. Inputs : a, b representing Numbers as arguments from the request. Outputs: The result of those two numbers being sent thru The Russuan Peasant's Algorithm. """ key = a,b result = fake_database.russian(a,b) CACHE[key] = result print result
def multiplyHandler(a, b): key = (a,b) cachedAnswer = CACHE.get(key) if cachedAnswer: return cachedAnswer else: result = fake_database.russian(a, b) updateLastMultiplied(a,b,result) done = CACHE.set(key, result) return 'Latest Result: {}'.format(result) lastMultipliedHandler()
def multiplyHandler(a, b): key = (a, b) cachedAnswer = cache.get(key) if cachedAnswer: return cachedAnswer else: result = fake_database.russian(a, b) updateLastMultiplied(a, b, result) done = cache.set(key, result) return 'Latest Result: {}'.format(result) lastMultipliedHandler()
def multiplyHandler(a,b): """ Inputs: a,b numbers as arguments from the request Outputs: The result of those numbers being sent through the Russian algorithm """ key = (a,b) cachedAnswer = CACHE.get(key) if cachedAnswer: return cachedAnswer else: result = fake_database.russian(a,b) updateLastMultiplied(a,b,result) done = CACHE.set(key,result) return "Last Result: {}".format(result) lastMultipliedHandler()
def multiply_handler(a, b): """ Inputs : a, b representing Number as arguments from the request Outputs: The result of those two number being sent thru The Russian's Peasant's Algorithm """ cache_key = (a, b) if cache_key in CACHE: print CACHE[cache_key] else: result = fake_database.russian(a, b) update_last_multiplied(a, b, result) CACHE[cache_key] = result print 'Latest Result: {}'.format(result) last_multiplied_handler()
def multiplyHandler(left, right): #Inputs: a, b representing Numbers as arguments from the request #Outputs: The result of those two numbers being sent through # The Russian Peasant's Algorithm. key = (left, right) # tuple to check if already know answer if key in CACHE: # already calculated. Return answer without calculating print("been there, done that") answer = CACHE[key] print(lastMultipliedHandler()) else: # Not done this before, Need to calculate answer print("this is new") answer = db.russian(left, right) updateLastMultiplied(left, right, answer) CACHE[key] = answer # store answer in case we are asked again print("Latest Result: {} " .format(answer)) lastMultipliedHandler() # this produces the latest results - maximum of 5 return answer
def multiplyHandler(a, b): """ Write this function. Input: a, b representing Numbers as arguments from the request Outputs: The result of those two numbers being sent thru The Russian Peasant's Algorithm :return: """ key = (a, b) cachedAnswer = cache.get(key) if cachedAnswer: return cachedAnswer else: result = fake_database.russian(a, b) updateLastMultiplied(a, b, result) done = cache.set(key, result) return 'Latest Result: {}'.format(result) lastMultipliedHandler()
def multiplyHandler(left, right): #Inputs: a, b representing Numbers as arguments from the request #Outputs: The result of those two numbers being sent through # The Russian Peasant's Algorithm. key = (left, right) # tuple to check if already know answer if key in CACHE: # already calculated. Return answer without calculating print("been there, done that") answer = CACHE[key] print(lastMultipliedHandler()) else: # Not done this before, Need to calculate answer print("this is new") answer = db.russian(left, right) updateLastMultiplied(left, right, answer) CACHE[key] = answer # store answer in case we are asked again print("Latest Result: {} ".format(answer)) lastMultipliedHandler( ) # this produces the latest results - maximum of 5 return answer
def multiplyHandler(a, b): """ Write this function. Inputs : a, b representing Numbers as arguments from the request. Outputs: The result of those two numbers being sent thru The Russuan Peasant's Algorithm. store answer in CACHE. also have a key of "last5" and val is a list. """ cache_key = (a, b) if cache_key in CACHE: answer = CACHE.get(cache_key) else: answer = fake_database.russian(a, b) CACHE[cache_key] = answer updateLastMultiplied(a, b, answer) return answer
def multiplyHandler(a, b): """ Write this function. Inputs : a, b representing Numbers as arguments from the request. Outputs: The result of those two numbers being sent thru The Russuan Peasant's Algorithm. store answer in CACHE. also have a key of "last5" and val is a list. """ cache_key = (a,b) if cache_key in CACHE: answer = CACHE.get(cache_key) else: answer = fake_database.russian(a,b) CACHE[cache_key] = answer updateLastMultiplied(a,b, answer) return answer