Lauren12311
Badges: 14
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
Report Thread starter 2 years ago
#1
could someone please message me and take a look at a question I have on probabilities in python please
0
reply
Hypocritic
Badges: 10
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#2
Report 2 years ago
#2
Sure
0
reply
Lauren12311
Badges: 14
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#3
Report Thread starter 2 years ago
#3
Two ants are independently placed uniformly at random on a disc of radius 1. Write a function that takes one argument, a distance and returns an estimate of
the probability that the ants are less than distance d apart.
0
reply
tc03
Badges: 5
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#4
Report 2 years ago
#4
(Original post by Lauren12311)
Two ants are independently placed uniformly at random on a disc of radius 1. Write a function that takes one argument, a distance and returns an estimate of
the probability that the ants are less than distance d apart.
This should work:
Spoiler:
Show
def findProbability(dist):
circumference = 3.14*2
# The circumference is pi*d therefore pi*(2r)
# Pi has been shortened to 3.14

probability = dist/circumference
# Calculate probability

if probability > 1:
return "Distance is too large"
else:
return probability

# Example of use
print(findProbability(3))
1
reply
Lauren12311
Badges: 14
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#5
Report Thread starter 2 years ago
#5
(Original post by troync3)
This should work:
Spoiler:
Show
def findProbability(dist):
circumference = 3.14*2
# The circumference is pi*d therefore pi*(2r)
# Pi has been shortened to 3.14

probability = dist/circumference
# Calculate probability

if probability > 1:
return "Distance is too large"
else:
return probability

# Example of use
print(findProbability(3))
This is brilliant thank you! I need to now get it to try every distance 1-100 see which is successful and divide that by 100 to get the average distance do you know how I’d add that in
0
reply
tc03
Badges: 5
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#6
Report 2 years ago
#6
(Original post by Lauren12311)
This is brilliant thank you! I need to now get it to try every distance 1-100 see which is successful and divide that by 100 to get the average distance do you know how I’d add that in
This should do what you need:
Spoiler:
Show
def findProbability(dist):
circumference = 3.14*2
# The circumference is pi*d therefore pi*(2r)
# Pi has been shortened to 3.14

probability = dist/circumference
# Calculate probability

if probability > 1:
return "Distance is too large"
else:
return probability

for i in range (1, 101):
totalProbability = totalProbability + findProbability(i)

avgProbability = totalProbability / 100
print (avgProbability)
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

How would you describe the quality of the digital skills you're taught at school?

Excellent (18)
8.33%
Okay (64)
29.63%
A bit lacking (81)
37.5%
Not good at all (53)
24.54%

Watched Threads

View All