Skip to content

Instantly share code, notes, and snippets.

@halexus
Last active April 7, 2019 08:16
Show Gist options
  • Save halexus/b1168ab4df948b56d871c550b9f14845 to your computer and use it in GitHub Desktop.
Save halexus/b1168ab4df948b56d871c550b9f14845 to your computer and use it in GitHub Desktop.
Aufgabe 23 UE Wahrscheinlichkeitstheorie
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Aufgabe 23\n",
"\n",
"Die Wahrscheinlichkeiten, die Augenzahlen $i = 1, \\dots, 6$ beim Werfen eines gezinkten Würfels zu erhalten seien $p_1 = p_2 = p_3 = p_4 = p_5 = \\frac{1}{7}, p_6 = \\frac{2}{7}$.\n",
"Der Würfel wird zweimal geworfen. Berechnen Sie den Erwartungswert der Augensumme.\n",
"***"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"import statistics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ich verwende die Funktion [`random.choices`](https://docs.python.org/3/library/random.html#random.choices) um zwei Würfe mit dem gezinkten Würfel durchzuführen. Als Gewichte fungieren die gewünschten Wahrscheinlichkeiten für die Zahlen.\n",
"\n",
"[`statistics.mean`](https://docs.python.org/3/library/statistics.html#statistics.mean) berechnet den arithmetischen Mittelwert einer Liste."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7.713106"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N=1000000 # Anzahl der Würfe\n",
"statistics.mean(sum(random.choices(range(1, 7), (1, 1, 1, 1, 1, 2), k=2)) for _ in range(N))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment