Random numbers in Python

I run the following Python code:

1
2
3
4
5
import random
x = 0
for i in range(0, 100):
    x += random()
print(x)

What is the probability that a number greater than 45 will be printed?

0.958 0.993 0.55 0.871 None of these 0

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Alex Li
Jun 5, 2015

Although the random module has been imported, the random method of the module has not. Thus, the code will result in an error.

Crap, I accidentally said "None of these", because I thought you meant that no number will be printed, but I guess in that case 0% is technically correct.

Brock Brown - 5 years, 12 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...