tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

Minor change to coinflip logic

Open slawdogporsche opened this issue 3 years ago • 0 comments
trafficstars

The plt render should be moved back one indentation, since you're really only interested in the final result and it saves you 5000 unnecessary renders

def monte_carlo(n): results = 0 for i in range(n): flip_result = coin_flip() results = results + flip_result

	prob_value = results/(i+1)

	list1.append(prob_value)

plt.axhline(y=0.5, color ='r', linestyle='-')
plt.xlabel("Iterations")
plt.ylabel("Probability")
plt.plot(list1)

return results/n

slawdogporsche avatar Jun 05 '22 20:06 slawdogporsche