Files
learn-python3/notebooks/beginner/exercises/14_debugging_exercise.ipynb
2023-04-22 14:55:09 +03:00

65 lines
1.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Identifying bugs in code\n",
"The following `stripped_reversed_lowercase` function contains at least one bug. You can see this by running the code in the cell below which tests the functionality of the `stripped_reversed_lowercase` function.\n",
"\n",
"Set trace at the beginning of `stripped_reversed_lowercase` and use debugger to solve the bug(s). Execute the code line by line and print variables used in the function to understand what's going wrong. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def stripped_reversed_lowercase(original):\n",
" # Set a breakpoint here and start debugging\n",
" # from IPython.core.debugger import Pdb; Pdb().set_trace()\n",
" stripped = original.lstrip()\n",
" reversed = \" \".join(reversed(stripped))\n",
" reversed.lower()\n",
" return reversed"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": false
},
"outputs": [],
"source": [
"# Let's verify it works\n",
"original = \" \\n Original String \"\n",
"result = stripped_reversed_lowercase(original)\n",
"assert result == \"gnirts lanigiro\""
]
}
],
"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.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}