examples = [([0,0],0),([0,1],0),([1,0],0),([1,1],1)] weights, bias = [0.0,0.0], 0.0 for epoch in range(20): errors = 0 for x,target in examples: predicted = int(sum(w*v for w,v in zip(weights,x,strict=True))+bias >= 0) error = target-predicted if error: weights = [w+error*v for w,v in zip(weights,x,strict=True)] bias += error errors += 1 if errors == 0: break print([int(sum(w*v for w,v in zip(weights,x,strict=True))+bias >= 0) for x,_ in examples])