Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 76 additions & 4 deletions lab-python-error-handling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,90 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "cc2c441d-9dcf-4817-b097-cf6cbe440846",
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"def get_unique_list(lst):\n",
" try:\n",
" if not isinstance(lst, list):\n",
" raise TypeError(\"El argumento debe ser una lista\")\n",
" return list(set(lst))\n",
" except Exception as e:\n",
" print(f\"Error en get_unique_list: {e}\")\n",
" return []\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "270d81b7",
"metadata": {},
"outputs": [],
"source": [
"def count_case(text):\n",
" try:\n",
" if not isinstance(text, str):\n",
" raise TypeError(\"El argumento debe ser un string\")\n",
" upper = sum(1 for c in text if c.isupper())\n",
" lower = sum(1 for c in text if c.islower())\n",
" return (upper, lower)\n",
" except Exception as e:\n",
" print(f\"Error en count_case: {e}\")\n",
" return (0, 0)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d9668ba3",
"metadata": {},
"outputs": [],
"source": [
"import string\n",
"\n",
"def remove_punctuation(sentence):\n",
" try:\n",
" if not isinstance(sentence, str):\n",
" raise TypeError(\"El argumento debe ser un string\")\n",
" return \"\".join(c for c in sentence if c not in string.punctuation)\n",
" except Exception as e:\n",
" print(f\"Error en remove_punctuation: {e}\")\n",
" return \"\"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "60af7416",
"metadata": {},
"outputs": [],
"source": [
"def word_count(sentence):\n",
" try:\n",
" if not isinstance(sentence, str):\n",
" raise TypeError(\"El argumento debe ser un string\")\n",
" cleaned = \"\".join(c for c in sentence if c not in string.punctuation)\n",
" return len(cleaned.split())\n",
" except Exception as e:\n",
" print(f\"Error en word_count: {e}\")\n",
" return 0\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69699366",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -66,7 +138,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down