PracticeForExam

This commit is contained in:
2024-12-05 23:20:53 +01:00
parent bcff76d934
commit a1e0e21582
5 changed files with 240 additions and 34 deletions

View File

@ -66,8 +66,49 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[100, 90, 80, 70, 60, 50, 40, 30, 20, 10]\n",
"[2, 3]\n",
"{'alma': 10, 'körte': 20, 'barack': 30}\n"
]
},
{
"ename": "TypeError",
"evalue": "len() takes exactly one argument (0 given)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 20\u001b[0m\n\u001b[1;32m 16\u001b[0m mydict\u001b[38;5;241m.\u001b[39mupdate({mylist[i] : \u001b[38;5;28mint\u001b[39m(mylist[i\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m])})\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28mprint\u001b[39m(mydict)\n\u001b[0;32m---> 20\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__doc__\u001b[39m)\n",
"\u001b[0;31mTypeError\u001b[0m: len() takes exactly one argument (0 given)"
]
}
],
"source": [
"tomb = [i*10 for i in range(10, 0,-1)]\n",
"\n",
"print(tomb)\n",
"\n",
"\n",
"lista1 = [-1, 2, 0, 3]\n",
"lista2 = [i for i in lista1 if i > 0]\n",
"\n",
"print(lista2)\n",
"\n",
"todict = 'alma,10,körte,20,barack,30'\n",
"mylist = todict.split(',')\n",
"mydict = {}\n",
"\n",
"for i in range(0, len(mylist)-1, 2):\n",
" mydict.update({mylist[i] : int(mylist[i+1])})\n",
"\n",
"print(mydict)\n",
"\n"
]
},
{
"cell_type": "markdown",
@ -83,7 +124,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -97,7 +138,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,