Question

In: Computer Science

Python program that simulates playing a game where a US penny (radius of 3/8 inches) is...

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 :)

Solutions

Expert Solution

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)


Related Solutions

Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
Write a Python program that simulates a restaurant ordering system where it stores multiple orders of...
Write a Python program that simulates a restaurant ordering system where it stores multiple orders of a dish and the price for each order stored into a list. The program will then print the receipt which includes list of orders and their price along with the subtotal before tax, the tax amount, and the final total. Also include tip suggestions for 10%, 15% and 20%. Use the format specifiers to make the price line up and the tip only 2...
6. A and B are playing a short game of ping pong where A serves 3...
6. A and B are playing a short game of ping pong where A serves 3 times and B also serves 3 times. If after these six points one of them is ahead the game ends, otherwise they go into a second phase. Suppose that A wins 70% of the points when they serve and 40% of the points when B serves. Let’s look at the first phase. a) (3 pts) Find the probability that A or B wins 0,...
This program is in Python ### simulates packets of data arriving at irregular times. The data...
This program is in Python ### simulates packets of data arriving at irregular times. The data gets ### read from the file and then you must place it in a queue where it will wait ### its turn to get processed. The "processing" happens in a threaded subroutine ### called "process_input_data". That function should pull data from the queue, ### hash the student ID number, and then store the data in a hash table which ### you have to implement....
“Triangle Guessing” game in Python The program accepts the lengths of three (3) sides of a...
“Triangle Guessing” game in Python The program accepts the lengths of three (3) sides of a triangle as input . The program output should indicate if the triangle is a right triangle, an acute triangle, or an obtuse triangle. Make sure each side of the triangle is a positive integer. Use try/except for none positive integer input. validating the triangle. That is the sum of the lengths of any two sides of a triangle is greater than the length of...
Objective: Write a program which simulates a hot potato game. In this version of a classic...
Objective: Write a program which simulates a hot potato game. In this version of a classic game, two or more players compete to see who can hold onto a potato the longest without getting caught. First the potato is assigned a random value greater than one second and less than three minutes both inclusive. This time is the total amount of time the potato may be held in each round. Next players are put into a circular list. Then each...
You will write a program using Python that simulates an Automatic Teller Machine (ATM). For this...
You will write a program using Python that simulates an Automatic Teller Machine (ATM). For this program, your code can have user defined functions (but not required), the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Requirements: There is a customer with the following credential and can only access the system if the Access Code is correct: • Name: Peter Parker, Access Code: 2222 • When the program...
You are playing a version of the roulette game, where the pockets are from 0 to...
You are playing a version of the roulette game, where the pockets are from 0 to 10 and even numbers are red and odd numbers are black (0 is green). You spin 3 times and add up the values you see. What is the probability that you get a total of 15 given on the first spin you spin a 2? What about a 3? Solve by simulation and analytically.
In this python program , you are to build a trivia game. The game should present...
In this python program , you are to build a trivia game. The game should present each question – either in order or randomly – to the player, and display up to four possible answers. The player is to input what they believe to be the correct answer.   The game will tell the player if they got it right or wrong and will display their score. If they got it right, their score will go up. If they got it...
Python program that simulates the rolling a die until the number 5 is first obtained. Repeat...
Python program that simulates the rolling a die until the number 5 is first obtained. Repeat the experiment 10,000 times and print out the “Average Number of Rolls to Obtain a Six on a Die”, along with the average value. Include the average number of rolls your program calculates as a comment Please use comments to better explain what is happening
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT