Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Global variable solution in Uncategorized category for Number Guess by Amachua
def checkio(attempts):
# Define as global the guessed values and the remaining divisors.
global values, numbers
# If it's the first call of the function. Update the two lists.
# Otherwise it will just update the guessed values.
if len(attempts) == 1:
numbers = [i for i in range(2,10) if not i == attempts[0][1]]
values = [i for i in range(1,101) if i%attempts[0][1] == attempts[0][0]]
else:
values = [i for i in values if i%attempts[-1][1] == attempts[-1][0]]
# Return the divisor and the guessed value.
value, number = values.pop(0), numbers.pop(0)
return (number, value)
Sept. 22, 2013
Comments: