#!/usr/bin/env python3 import random, math inside = 0 total = 10000000 for i in range(0, total): x = random.random() y = random.random() z = random.random() t = random.random() if math.sqrt(x**2 + y**2 + z**2 + t**2) < 1.0: # will also work: # if x**2 + y**2 + z**2 + t**2 < 1.0: inside += 1 area = float(inside) / total*(2**4) print("volume of tesseract", 2**4) print("volume 4-sphere", area)