#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 17 15:23:56 2024

@author: sam
"""

import numpy as np



def f(x):
    return np.sin(x)**2

def MCI(f,a,b): # monte-carlo integration of function f between bounds a to b
    U = np.random.uniform(a,b,10000) # generates 10,000 uniform random values between 0 and pi
    I = 0 # create variable I
    for i in range(len(U)): # loop through all uniform random numbers
        I += f(U[i]) # adds the function value of each uniform random numbers to I
    I *= (b-a)/len(U) # multiplies I by the difference of endpoints / the number of uniform random numbers
    return I



print(MCI(f,0,np.pi))