input: Write a function to perform linear regression for predicting numbers in a given dataset using Python. The function should take two lists as input, X and Y, where X represents the independent variable and Y represents the dependent variable. The function should return the predicted value of Y for a new value of X.
  
  assert linear_regression([1,2,3,4,5], [3,5,7,9,13]) == 17.0
  assert linear_regression([2,3,4,5,6], [5,7,9,11,13]) == 15.0
  assert linear_regression([1,2,4,5], [3,7,13,19]) == 31.0
  assert linear_regression([1,3,5,7], [2,4,6,8]) == 10.0
output: def linear_regression(X, Y):
      n = len(X)
      sum_x = sum(X)
      sum_y = sum(Y)
      sum_xy = sum(x * y for x, y in zip(X, Y))
      sum_x2 = sum(x ** 2 for x in X)
      
      slope = (n * sum_xy - sum_x * sum_y) / (n * sum_x2 - sum_x ** 2)
      intercept = (sum_y - slope * sum_x) / n
      
      new_x = X[-1] + 1
      return slope * new_x + intercept