Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab done by Sergej at 29-01-25 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
248 changes: 202 additions & 46 deletions 2_conditional_statements.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -394,6 +427,11 @@
"## More examples"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
},
Expand All @@ -799,7 +955,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.1"
}
},
"nbformat": 4,
Expand Down