Skip to content

Instantly share code, notes, and snippets.

@halexus
Created April 3, 2019 15:21
Show Gist options
  • Save halexus/e24feb62ecddf66c998bb1cbe863f40f to your computer and use it in GitHub Desktop.
Save halexus/e24feb62ecddf66c998bb1cbe863f40f to your computer and use it in GitHub Desktop.
Beispiel 22 UE Wahrscheinlichkeitstheorie
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"****************************************************************************************************\n",
"-0.076795\n"
]
}
],
"source": [
"import random\n",
"N=1000000\n",
"gewinn={0:-1,\n",
" 1:1,\n",
" 2:2,\n",
" 3:3}\n",
"gesamtgewinn=0\n",
"for i in range(N):\n",
" if i%(N//100)==0: # Fortschrittsbalken; Gib 100 '*' aus um den Fortschritt der Simulation zu sehen\n",
" print(\"*\", end=\"\", flush=True) # flush=True => Ausgabe ohne Buffern\n",
" wurf = [random.randint(1,6) for _ in range(3)]\n",
" gewaehlte_zahl = random.randint(1,6)\n",
" gesamtgewinn+=gewinn[wurf.count(gewaehlte_zahl)]\n",
"print()\n",
"print(gesamtgewinn/N) # Durchschnittlicher Gewinn / Spiel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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