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
169 changes: 143 additions & 26 deletions 1_variables_operators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1327,10 +1327,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"type(x1) <class 'float'>\n",
"type(x2) <class 'str'>\n",
"type(x3) <class 'str'>\n",
"type(x4) <class 'bool'>\n",
"type(x5) <class 'str'>\n",
"type(x6) <class 'int'>\n"
]
}
],
"source": [
"print(\"type(x1)\", type(x1))\n",
"print(\"type(x2)\", type(x2))\n",
"print(\"type(x3)\", type(x3))\n",
"print(\"type(x4)\", type(x4))\n",
"print(\"type(x5)\", type(x5))\n",
"print(\"type(x6)\", type(x6))"
]
},
{
"cell_type": "markdown",
Expand All @@ -1344,7 +1364,11 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"#The x1 is 'float' while the x3 is 'str'.\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -1357,8 +1381,25 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for -: 'str' and 'float'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mTypeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[6]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mx3-x1\u001b[39m\u001b[33m\"\u001b[39m, \u001b[43mx3\u001b[49m\u001b[43m \u001b[49m\u001b[43m-\u001b[49m\u001b[43m \u001b[49m\u001b[43mx1\u001b[49m) \n",
"\u001b[31mTypeError\u001b[39m: unsupported operand type(s) for -: 'str' and 'float'"
]
}
],
"source": [
"print(\"x3-x1\", x3 - x1) \n",
"# since the x1 is 'float' but the x3 is 'str'. Then it makse an error\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -1369,10 +1410,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# the x4 is 'bool' but the x5 is 'str'.\n",
"\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -1383,10 +1427,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for -: 'str' and 'bool'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mTypeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mx5 - x4\u001b[39m\u001b[33m\"\u001b[39m, \u001b[43mx5\u001b[49m\u001b[43m \u001b[49m\u001b[43m-\u001b[49m\u001b[43m \u001b[49m\u001b[43mx4\u001b[49m)\n\u001b[32m 2\u001b[39m \u001b[38;5;66;03m# the x4 is 'bool' but the x5 is 'str'. Then it makes an error. \u001b[39;00m\n",
"\u001b[31mTypeError\u001b[39m: unsupported operand type(s) for -: 'str' and 'bool'"
]
}
],
"source": [
"print(\"x5 - x4\", x5 - x4)\n",
"# the x4 is 'bool' but the x5 is 'str'. Then it makes an error. "
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -1427,10 +1486,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You entered x1: 5 x2: 8\n",
"type(x1): <class 'str'>\n",
"type(x2): <class 'str'>\n"
]
}
],
"source": [
"x1 = input(\"Please enter an integer number: \")\n",
"x2 = input(\"Please enter another integer number: \")\n",
"print(\"You entered x1:\", x1, \" x2:\", x2)\n",
"print(\"type(x1):\", type(x1))\n",
"print(\"type(x2):\", type(x2))\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -1441,10 +1516,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You entered x1: 7 x2: 9\n",
"type(x1): <class 'int'>\n",
"type(x2): <class 'int'>\n"
]
}
],
"source": [
"x1 = int(input(\"Please enter an integer number: \"))\n",
"x2 = int(input(\"Please enter another integer number: \"))\n",
"print(\"You entered x1:\", x1, \" x2:\", x2)\n",
"print(\"type(x1):\", type(x1))\n",
"print(\"type(x2):\", type(x2))\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -1466,10 +1557,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x1 == x2: False\n",
"x1 == x2: True\n"
]
}
],
"source": [
"print(\"x1 == x2:\", x1 == x2)\n",
"x3 = x2 - x1\n",
"x1 = x1 + x3\n",
"print(\"x1 == x2:\", x1 == x2)"
]
},
{
"cell_type": "markdown",
Expand All @@ -1482,10 +1587,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, Ali Ghafari!\n"
]
}
],
"source": [
"name = input(\"Please enter your name: \")\n",
"family_name = input(\"Please enter your family name: \")\n",
"print(\"Hello,\", name, family_name + \"!\")\n"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -1666,7 +1783,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -1680,7 +1797,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.0"
}
},
"nbformat": 4,
Expand Down