diff --git a/2_conditional_statements.ipynb b/2_conditional_statements.ipynb index 50314f3..e80a025 100644 --- a/2_conditional_statements.ipynb +++ b/2_conditional_statements.ipynb @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -103,9 +103,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b is greater\n" + ] + } + ], "source": [ "if a > b: # Here we are trying to find if a is greater than b\n", " print('a is greater')\n", @@ -167,9 +175,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b is greater than a or both are equal\n" + ] + } + ], "source": [ "if a > b: # Here we are trying to find if which is greater, a or b\n", " print('a is greater') \n", @@ -179,9 +195,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b is greater\n" + ] + } + ], "source": [ "if a > b: # Here we are trying to find if a is greater than b\n", " print('a is greater')\n", @@ -214,9 +238,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b is greater\n", + "Done!\n" + ] + } + ], "source": [ "if a > b: # Here we are trying to find if a is greater than b\n", " print('a is greater')\n", @@ -394,6 +427,11 @@ "## More examples" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -403,9 +441,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number is positive.\n" + ] + } + ], "source": [ "number = int(input(\"Enter a number: \"))\n", "\n", @@ -433,9 +479,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your grade is: F\n" + ] + } + ], "source": [ "percentage = float(input(\"Enter the percentage: \"))\n", "\n", @@ -493,9 +547,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number is positive and even.\n" + ] + } + ], "source": [ "number = int(input(\"Enter a number: \"))\n", "\n", @@ -532,9 +594,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "c is the greatest\n" + ] + } + ], "source": [ "a = 5 \n", "b = 10\n", @@ -628,9 +698,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number is positive.\n", + "The number is odd.\n" + ] + } + ], "source": [ "number = int(input(\"Enter a number: \"))\n", "\n", @@ -677,10 +756,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a is greater than b\n" + ] + } + ], + "source": [ + "a = int(input(\"Enter a number a = \"))\n", + "b = int(input(\"Enter a number b = \"))\n", + "if a > b:\n", + " print(\"a is greater than b\")\n", + "elif a < b:\n", + " print(\"b is greater than a\")\n", + "else:\n", + " print(\"a and b are equal\")" + ] }, { "cell_type": "markdown", @@ -697,10 +793,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your grade is: 89 Grade: B\n" + ] + } + ], + "source": [ + "grad = int(input(\"Enter your grade: \"))\n", + "print(\"Your grade is:\", grad, \"Grade: \", end=\" \")\n", + "if grad >= 90:\n", + " print(\"A\")\n", + "elif grad >= 80:\n", + " print(\"B\")\n", + "elif grad >= 70:\n", + " print(\"C\")\n", + "elif grad >= 60:\n", + " print(\"D\")\n", + "else:\n", + " print(\"F\")" + ] }, { "cell_type": "markdown", @@ -749,10 +866,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The character รค is not an english letter.\n" + ] + } + ], + "source": [ + "vowel = \"aeiouy\"\n", + "consonant = \"bcdfghjklmnpqrstvwxz\"\n", + "c = input(\"Enter a letter : \")\n", + "if c.lower() in vowel:\n", + " print(f\"The letter {c} is a vowel.\")\n", + "elif c.lower() in consonant:\n", + " print(f\"The letter {c} is a consonant.\")\n", + "else:\n", + " print(f\"The character {c} is not an english letter.\")" + ] }, { "cell_type": "markdown", @@ -777,15 +912,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number -565 is odd.\n" + ] + } + ], + "source": [ + "n = input(\"Enter an integer number: \")\n", + "if n.isdigit() or (n[0] == \"-\" and n[1:].isdigit()):\n", + " n = int(n)\n", + " if n % 2 == 0:\n", + " print(f\"The number {n} is even.\")\n", + " elif n % 2 != 0:\n", + " print(f\"The number {n} is odd.\")\n", + " else:\n", + " print(f\"The number {n} is zero.\")\n", + "else:\n", + " print(f\"{n} is not enter an integer number.\")\n", + " " + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -799,7 +955,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.1" } }, "nbformat": 4,