goal = 42 # Label
weight = 0.0
input_val = 0.5
iteration = 0

for iteration in range(15):
# The output of the algorithm
output = input_val * weight
# Calculate the error. Negative errors would hinder the learning process, so errors are squared to ensure that the error metric is positiv
error = (output - goal) ** 2
# Calculate the difference between the output and the goal value
delta = output - goal
# Calculate weight delta, the value with wich we alter the weight
weight_delta = input_val * delta
# Adjust the weight
weight = weight - weight_delta
# Update the iteration number
iteration = iteration + 1
# Print out the results of the iteration
print('----- Iteration {} -----'.format(iteration))
print('Error: {}'.format(error), 'Output: {}'.format(output))