113 lines
2.9 KiB
Plaintext
113 lines
2.9 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"### Debugowanie – Najważniejsze Informacje\n",
|
||
"Debugowanie to proces identyfikowania i usuwania błędów (bugów) w kodzie. Poniżej kluczowe pojęcia i techniki, które pomagają skutecznie debugować.\n",
|
||
"\n",
|
||
"#### Narzędzia do kontrolowania wykonywania kodu podczas debugowania:\n",
|
||
"\n",
|
||
"**Breakpoint** – punkt w kodzie, w którym debugger zatrzymuje wykonywanie programu.\n",
|
||
"\n",
|
||
"**Step Over** – wykonuje bieżącą linię i przechodzi do następnej.\n",
|
||
"\n",
|
||
"**Step Into** – wchodzi do wywoływanej funkcji, umożliwiając jej analizę.\n",
|
||
"\n",
|
||
"**Step Out** – kończy analizę funkcji i wraca do poziomu wywołującego.\n",
|
||
"\n",
|
||
"#### Wskazówki\n",
|
||
"\n",
|
||
"* Podczas debugowania warto skorzystać z **Debug Console**, pozwalającej na wywołanie kodu w Pythonie na podstawie obecnego stanu programu.\n",
|
||
"* Debugujmy zawsze na **przykładowych**, **prostych** danych! (zanim przejdziemy do docelowej, na ogół obszerniejszej wersji danych)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 26,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import random\n",
|
||
"\n",
|
||
"\n",
|
||
"def perform_random_operation(a, b):\n",
|
||
" choice = random.choice([1, 2, 3])\n",
|
||
"\n",
|
||
" if choice == 1:\n",
|
||
" output = a + b\n",
|
||
" elif choice == 2:\n",
|
||
" output = a * b\n",
|
||
" else:\n",
|
||
" output = a / b\n",
|
||
" \n",
|
||
" return output"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 27,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"def perform_random_operation_elementwise(list_a, list_b):\n",
|
||
" res = []\n",
|
||
"\n",
|
||
" for a, b in zip(list_a, list_b):\n",
|
||
" value = perform_random_operation(a, b)\n",
|
||
" res.append(value)\n",
|
||
"\n",
|
||
" return res"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 29,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"[1, 1.4, 7.5, 4.6, 45, 130, 500, 0, 400]"
|
||
]
|
||
},
|
||
"execution_count": 29,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"first = [1, 5, 2, 5, 3, 10, 20, 0, 4]\n",
|
||
"second = [1, 7, 15, 23, 15, 13, 25, 24, 100]\n",
|
||
"\n",
|
||
"# first = [0, 0, 0]\n",
|
||
"# second = [0, 1, 2]\n",
|
||
"\n",
|
||
"perform_random_operation_elementwise(second, first)"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "base",
|
||
"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.11.5"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 2
|
||
}
|