import numpy as np

def f(x):
    return np.exp(x)

a = 0
b = 1

n_values = [1, 2, 3, 4, 5, 6]

for n in n_values:
    
    x = np.linspace(a, b, n + 1)
    
    if n == 1:  
        weights = np.array([1, 1])
    elif n == 2:  
        weights = np.array([1, 4, 1])
    elif n == 3:  
        weights = np.array([1, 3, 3, 1])
    elif n == 4:  
        weights = np.array([7, 32, 12, 32, 7])
    elif n == 5:  
        weights = np.array([19, 75, 50, 50, 75, 19])
    else:
        weights = np.array([41, 63, 27, 272, 27, 63, 41])
    
    p = np.sum(weights)
    
    result = np.sum(weights * f(x)) / p
    
    print(f"n = {n}, 积分结果: {result}")
