# python

Watch
Announcements
#1
could someone please message me and take a look at a question I have on probabilities in python please
0
2 years ago
#2
Sure
0
#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
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
#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
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
X

new posts Back
to top
Latest
My Feed

### Oops, nobody has postedin the last few hours.

Why not re-start the conversation?

see more

### See more of what you like onThe Student Room

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

### Poll

Join the discussion

#### 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%