import random as rd
import numpy as np
def f(x, y, z):
return x+y+z
if __name__=="__main__":
N=100000
rd.seed()
xlim=[0, 1]
ylim=[0, 1]
zlim=[0, 1]
sum=0.
for i in range(N):
x=xlim[0]+(xlim[1]-xlim[0])*rd.random()
y=ylim[0]+(ylim[1]-ylim[0])*rd.random()
z=zlim[0]+(zlim[1]-zlim[0])*rd.random()
sum+=f(x, y, z)
sum=sum*(xlim[1]-xlim[0])*(ylim[1]-ylim[0])*(zlim[1]-zlim[0])/N
print("integral f(x, y, z)=x+y+z")
print("from x=0 to 1, from y=0 to 1, from z=0 to 1:")
print(sum)