Zum Test gebe ich im Terminal folgendes ein::
Code: Alles auswählen
python3
Nun kann ich mir auf folgende Weise eine normalverteilte Zufallszahl auf folgende Weise ausgeben:
Code: Alles auswählen
# import the random module
import random
print(random.normalvariate(5, 0.1))
Code: Alles auswählen
4.953696677831711
Code: Alles auswählen
# import the random module
import random
# determining the values of the parameters
mu = 100
sigma = 50
# using the normalvariate() method
print(random.normalvariate(mu, sigma))
Code: Alles auswählen
136.00273528689257
Code: Alles auswählen
# import the required libraries
import- random
import matplotlib.pyplot as plt
# store the random numbers in a
# list
nums = []
mu = 100
sigma = 50
for i in range(100):
temp = random.normalvariate(mu, sigma)
nums.append(temp)
# plotting a graph
plt.plot(nums)
plt.show()
Fehlermeldung:
Code: Alles auswählen
>>> # import the required libraries
... import- random
File "<stdin>", line 2
import- random
^
SyntaxError: invalid syntax
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib'
>>>
... # store the random numbers in a
... # list
... nums = []
>>> mu = 100
>>> sigma = 50
>>>
... for i in range(100):
... temp = random.normalvariate(mu, sigma)
... nums.append(temp)
...
... # plotting a graph
... plt.plot(nums)
File "<stdin>", line 7
plt.plot(nums)
^
SyntaxError: invalid syntax
>>> plt.show()