sq_02_python_data_science/jupyter_book/01_wiederholung.ipynb

95 lines
2.1 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"id": "1a44722c-9586-4418-ad7f-8a3c964a9db8",
"metadata": {},
"source": [
"# Wiederholung\n",
"\n",
"Um alle Teilnehmer auf den gleichen Stand zu bringen fangen wir dort an, wo der erste Kurs geendet hat."
]
},
{
"cell_type": "markdown",
"id": "5246ab8c-2b98-48f0-9dc5-a36d99ecff60",
"metadata": {},
"source": [
"## Packages, Funktionen, Arrays und Rechnen"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c04b1fca-a1f5-4ba2-90a8-216c3cc41556",
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"random.seed(42)\n",
"\n",
"def rand_numbers(n, start, end):\n",
" \"\"\" Erzeugt einen Array mit Zufallszahlen mit 2 Nachkommastellen\n",
" n\n",
" Anzahl der erzeugten Zufallszahlen\n",
" \n",
" start\n",
" Kleinste mögliche Zahl (inklusiv)\n",
" \n",
" end\n",
2023-10-19 09:35:19 +02:00
" Größte mögliche Zahl (inklusiv)\n",
" \"\"\"\n",
2023-10-19 09:35:19 +02:00
" digits = 2\n",
" factor = 10 ** digits\n",
" result = []\n",
" for i in range(n):\n",
" result.append(random.randint(start * factor, end * factor) / factor)\n",
" \n",
" return result "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ff484198-3f23-439c-a17d-790e24d74c7e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[-0.13, -0.29, -0.61, -0.45, 0.95, -0.14, -0.74, -0.77, -0.03, -0.76]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rand_numbers(10, -1, 1)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}