Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download

Jupyter notebook benford.ipynb

Project: NYCWiC
Views: 169
Kernel: Python 3 (Anaconda)

Benford's Law Example

import numpy as np import matplotlib.pyplot as plt
# first digit of a number def firstDigit(n): string = str(n) return int(string[0])
# exponentiate and track first digit at each step def benford(num,iter): arrNum = [num] for i in range(iter): arrNum.append(arrNum[-1]*num) return [firstDigit(n) for n in arrNum]
# histogram for 2.04 plt.hist(benford(2.04,100),bins=9) plt.show()
Image in a Jupyter notebook