In: Computer Science
Python program that simulates playing a game where a US penny (radius of 3/8 inches) is tossed into a board with a 1-inch by 1-inch square. The player wins only if the penny lands entirely within the square. Estimate the probability of winning by repeating the game 1,000 times. Record the estimate of the winning chance as a comment. Also, find the winning probability.
Please use comments to better explain :)
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
from random import *
rad = 3/8
wins = 0
for i in range(10000):
x = random() # Generating Random Coordinates for Centre of circle
y = random()
# Checking Weather The perimeter of circle wins+=1 #is inside the square or not
if x+rad < 1 and x-rad > 0 and y+rad < 1 and y-rad > 0:
wins += 1
probability = wins/10000 # Calculating the Probability by Given Forumula
print("The Probability is:", probability)