├── README.md ├── pandas ├── data │ ├── sample_csv.csv │ ├── grades.csv │ └── grades-2.csv ├── imgs │ └── numpy-vs-pandas.png └── grades.csv ├── python ├── images │ ├── bar.png │ ├── bmi.png │ ├── for.png │ ├── if.png │ ├── nlp.png │ ├── set.png │ ├── axis.png │ ├── class.png │ ├── list.png │ ├── mesh.png │ ├── plot.png │ ├── relu.png │ ├── rules.png │ ├── sets.png │ ├── text.png │ ├── title.png │ ├── tuple.png │ ├── union.png │ ├── while.png │ ├── arrows.png │ ├── brother.png │ ├── cylindar.png │ ├── decision.png │ ├── div-q-r.png │ ├── function.png │ ├── gaussian.png │ ├── if-else.png │ ├── joystick.png │ ├── lambda.png │ ├── matmul.png │ ├── matrix.png │ ├── meshgrid.png │ ├── neuron.png │ ├── parcel.png │ ├── plot2d.png │ ├── python.png │ ├── scatter.png │ ├── shelves.png │ ├── string-1.png │ ├── string-2.png │ ├── string-3.png │ ├── string-4.png │ ├── string-5.png │ ├── uniform.png │ ├── variable.png │ ├── add-matrix.png │ ├── comparison.png │ ├── data-types.png │ ├── dictionary.png │ ├── difference.png │ ├── function-0.png │ ├── histogram.png │ ├── iter-next.png │ ├── matplotlib.png │ ├── plot-style.png │ ├── precedence.png │ ├── figure-axes.png │ ├── for-one-line.png │ ├── gaussian-dist.png │ ├── housesbanner.png │ ├── if-elif-else.png │ ├── if-example-1.png │ ├── if-example-2.png │ ├── if-example-3.png │ ├── if-one-line.png │ ├── intersection.png │ ├── list-indexing.png │ ├── list-insert.png │ ├── list-slicing.png │ ├── list_methodes.png │ ├── numpy-dtype.png │ ├── set-example1.png │ ├── set-example2.png │ ├── set-example3.png │ ├── set-methods.png │ ├── table-grade.png │ ├── type-variable.png │ ├── class-example-1.png │ ├── class-example-2.png │ ├── class-example-3.png │ ├── class-example-4.png │ ├── data-structures.png │ ├── loop-example-1.png │ ├── loop-example-2.png │ ├── loop-example-3.png │ ├── math-operations.png │ ├── scatter-example.png │ ├── score-students.png │ ├── string_methodes.png │ ├── tuple-example1.png │ ├── tuple-example2.png │ ├── tuple-example3.png │ ├── 10-fingers-typing.jpg │ ├── add-rowvec-colvec.png │ ├── binary-operators.png │ ├── boolean-ops-numpy.PNG │ ├── condition-function.png │ ├── define-make-call.png │ ├── dictionary-example.png │ ├── dictionary-methods.png │ ├── function-example1.png │ ├── function-example2.png │ ├── function-example3.png │ ├── function-example4.png │ ├── list-neg-indexing.png │ ├── comparison-operators.png │ ├── dictionary-example2.png │ ├── dictionary-example3.png │ ├── inheritance-example.png │ ├── comparison-operators-numpy.png │ └── numpylogo_dark.svg ├── lectures │ ├── section-0-intro-python.pdf │ ├── section-0.5-intro-flowchart.pdf │ ├── .ipynb_checkpoints │ │ ├── section-1-variable-checkpoint.ipynb │ │ ├── section-1-variables-checkpoint.ipynb │ │ ├── section-12-function-checkpoint.ipynb │ │ ├── section-2-operators-checkpoint.ipynb │ │ └── section-4-comparison-checkpoint.ipynb │ ├── section-1-variables.ipynb │ ├── section-2-operators.ipynb │ └── section-4-comparison.ipynb └── templates │ ├── section-1-variables.ipynb │ ├── section-4-comparison.ipynb │ ├── section-2-operators.ipynb │ ├── section-6-loops.ipynb │ └── section-5-conditional-statements.ipynb ├── assets └── images │ ├── axes.png │ ├── mosaic.png │ ├── figure-axes.png │ ├── pandas-logo.png │ ├── numpy-vs-pandas.png │ ├── dataframe-series-2.png │ ├── dataframe-series.png │ └── matlabstyle-to-oo.png ├── numpy └── homework-numpy.pdf └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # Python for AI Course by Howsam 2 | -------------------------------------------------------------------------------- /pandas/data/sample_csv.csv: -------------------------------------------------------------------------------- 1 | 1, 2, 3, 4, 5 2 | 6, 7, 8, 9, 0 -------------------------------------------------------------------------------- /python/images/bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/bar.png -------------------------------------------------------------------------------- /python/images/bmi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/bmi.png -------------------------------------------------------------------------------- /python/images/for.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/for.png -------------------------------------------------------------------------------- /python/images/if.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/if.png -------------------------------------------------------------------------------- /python/images/nlp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/nlp.png -------------------------------------------------------------------------------- /python/images/set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/set.png -------------------------------------------------------------------------------- /assets/images/axes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/assets/images/axes.png -------------------------------------------------------------------------------- /python/images/axis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/axis.png -------------------------------------------------------------------------------- /python/images/class.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/class.png -------------------------------------------------------------------------------- /python/images/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/list.png -------------------------------------------------------------------------------- /python/images/mesh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/mesh.png -------------------------------------------------------------------------------- /python/images/plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/plot.png -------------------------------------------------------------------------------- /python/images/relu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/relu.png -------------------------------------------------------------------------------- /python/images/rules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/rules.png -------------------------------------------------------------------------------- /python/images/sets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/sets.png -------------------------------------------------------------------------------- /python/images/text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/text.png -------------------------------------------------------------------------------- /python/images/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/title.png -------------------------------------------------------------------------------- /python/images/tuple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/tuple.png -------------------------------------------------------------------------------- /python/images/union.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/union.png -------------------------------------------------------------------------------- /python/images/while.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/while.png -------------------------------------------------------------------------------- /assets/images/mosaic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/assets/images/mosaic.png -------------------------------------------------------------------------------- /numpy/homework-numpy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/numpy/homework-numpy.pdf -------------------------------------------------------------------------------- /python/images/arrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/arrows.png -------------------------------------------------------------------------------- /python/images/brother.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/brother.png -------------------------------------------------------------------------------- /python/images/cylindar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/cylindar.png -------------------------------------------------------------------------------- /python/images/decision.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/decision.png -------------------------------------------------------------------------------- /python/images/div-q-r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/div-q-r.png -------------------------------------------------------------------------------- /python/images/function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/function.png -------------------------------------------------------------------------------- /python/images/gaussian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/gaussian.png -------------------------------------------------------------------------------- /python/images/if-else.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/if-else.png -------------------------------------------------------------------------------- /python/images/joystick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/joystick.png -------------------------------------------------------------------------------- /python/images/lambda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/lambda.png -------------------------------------------------------------------------------- /python/images/matmul.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/matmul.png -------------------------------------------------------------------------------- /python/images/matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/matrix.png -------------------------------------------------------------------------------- /python/images/meshgrid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/meshgrid.png -------------------------------------------------------------------------------- /python/images/neuron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/neuron.png -------------------------------------------------------------------------------- /python/images/parcel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/parcel.png -------------------------------------------------------------------------------- /python/images/plot2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/plot2d.png -------------------------------------------------------------------------------- /python/images/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/python.png -------------------------------------------------------------------------------- /python/images/scatter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/scatter.png -------------------------------------------------------------------------------- /python/images/shelves.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/shelves.png -------------------------------------------------------------------------------- /python/images/string-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/string-1.png -------------------------------------------------------------------------------- /python/images/string-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/string-2.png -------------------------------------------------------------------------------- /python/images/string-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/string-3.png -------------------------------------------------------------------------------- /python/images/string-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/string-4.png -------------------------------------------------------------------------------- /python/images/string-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/string-5.png -------------------------------------------------------------------------------- /python/images/uniform.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/uniform.png -------------------------------------------------------------------------------- /python/images/variable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/variable.png -------------------------------------------------------------------------------- /python/images/add-matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/add-matrix.png -------------------------------------------------------------------------------- /python/images/comparison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/comparison.png -------------------------------------------------------------------------------- /python/images/data-types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/data-types.png -------------------------------------------------------------------------------- /python/images/dictionary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/dictionary.png -------------------------------------------------------------------------------- /python/images/difference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/difference.png -------------------------------------------------------------------------------- /python/images/function-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/function-0.png -------------------------------------------------------------------------------- /python/images/histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/histogram.png -------------------------------------------------------------------------------- /python/images/iter-next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/iter-next.png -------------------------------------------------------------------------------- /python/images/matplotlib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/matplotlib.png -------------------------------------------------------------------------------- /python/images/plot-style.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/plot-style.png -------------------------------------------------------------------------------- /python/images/precedence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/precedence.png -------------------------------------------------------------------------------- /assets/images/figure-axes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/assets/images/figure-axes.png -------------------------------------------------------------------------------- /assets/images/pandas-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/assets/images/pandas-logo.png -------------------------------------------------------------------------------- /pandas/imgs/numpy-vs-pandas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/pandas/imgs/numpy-vs-pandas.png -------------------------------------------------------------------------------- /python/images/figure-axes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/figure-axes.png -------------------------------------------------------------------------------- /python/images/for-one-line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/for-one-line.png -------------------------------------------------------------------------------- /python/images/gaussian-dist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/gaussian-dist.png -------------------------------------------------------------------------------- /python/images/housesbanner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/housesbanner.png -------------------------------------------------------------------------------- /python/images/if-elif-else.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/if-elif-else.png -------------------------------------------------------------------------------- /python/images/if-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/if-example-1.png -------------------------------------------------------------------------------- /python/images/if-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/if-example-2.png -------------------------------------------------------------------------------- /python/images/if-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/if-example-3.png -------------------------------------------------------------------------------- /python/images/if-one-line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/if-one-line.png -------------------------------------------------------------------------------- /python/images/intersection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/intersection.png -------------------------------------------------------------------------------- /python/images/list-indexing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/list-indexing.png -------------------------------------------------------------------------------- /python/images/list-insert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/list-insert.png -------------------------------------------------------------------------------- /python/images/list-slicing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/list-slicing.png -------------------------------------------------------------------------------- /python/images/list_methodes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/list_methodes.png -------------------------------------------------------------------------------- /python/images/numpy-dtype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/numpy-dtype.png -------------------------------------------------------------------------------- /python/images/set-example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/set-example1.png -------------------------------------------------------------------------------- /python/images/set-example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/set-example2.png -------------------------------------------------------------------------------- /python/images/set-example3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/set-example3.png -------------------------------------------------------------------------------- /python/images/set-methods.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/set-methods.png -------------------------------------------------------------------------------- /python/images/table-grade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/table-grade.png -------------------------------------------------------------------------------- /python/images/type-variable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/type-variable.png -------------------------------------------------------------------------------- /assets/images/numpy-vs-pandas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/assets/images/numpy-vs-pandas.png -------------------------------------------------------------------------------- /python/images/class-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/class-example-1.png -------------------------------------------------------------------------------- /python/images/class-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/class-example-2.png -------------------------------------------------------------------------------- /python/images/class-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/class-example-3.png -------------------------------------------------------------------------------- /python/images/class-example-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/class-example-4.png -------------------------------------------------------------------------------- /python/images/data-structures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/data-structures.png -------------------------------------------------------------------------------- /python/images/loop-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/loop-example-1.png -------------------------------------------------------------------------------- /python/images/loop-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/loop-example-2.png -------------------------------------------------------------------------------- /python/images/loop-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/loop-example-3.png -------------------------------------------------------------------------------- /python/images/math-operations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/math-operations.png -------------------------------------------------------------------------------- /python/images/scatter-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/scatter-example.png -------------------------------------------------------------------------------- /python/images/score-students.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/score-students.png -------------------------------------------------------------------------------- /python/images/string_methodes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/string_methodes.png -------------------------------------------------------------------------------- /python/images/tuple-example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/tuple-example1.png -------------------------------------------------------------------------------- /python/images/tuple-example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/tuple-example2.png -------------------------------------------------------------------------------- /python/images/tuple-example3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/tuple-example3.png -------------------------------------------------------------------------------- /assets/images/dataframe-series-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/assets/images/dataframe-series-2.png -------------------------------------------------------------------------------- /assets/images/dataframe-series.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/assets/images/dataframe-series.png -------------------------------------------------------------------------------- /assets/images/matlabstyle-to-oo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/assets/images/matlabstyle-to-oo.png -------------------------------------------------------------------------------- /pandas/data/grades.csv: -------------------------------------------------------------------------------- 1 | ,math,sport,art,farsi 2 | 0,20,NaN,19,20 3 | 1,15,20.0,18,18 4 | 2,15,20.0,18,19 5 | 3,20,20.0,18,18 6 | -------------------------------------------------------------------------------- /python/images/10-fingers-typing.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/10-fingers-typing.jpg -------------------------------------------------------------------------------- /python/images/add-rowvec-colvec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/add-rowvec-colvec.png -------------------------------------------------------------------------------- /python/images/binary-operators.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/binary-operators.png -------------------------------------------------------------------------------- /python/images/boolean-ops-numpy.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/boolean-ops-numpy.PNG -------------------------------------------------------------------------------- /python/images/condition-function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/condition-function.png -------------------------------------------------------------------------------- /python/images/define-make-call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/define-make-call.png -------------------------------------------------------------------------------- /python/images/dictionary-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/dictionary-example.png -------------------------------------------------------------------------------- /python/images/dictionary-methods.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/dictionary-methods.png -------------------------------------------------------------------------------- /python/images/function-example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/function-example1.png -------------------------------------------------------------------------------- /python/images/function-example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/function-example2.png -------------------------------------------------------------------------------- /python/images/function-example3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/function-example3.png -------------------------------------------------------------------------------- /python/images/function-example4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/function-example4.png -------------------------------------------------------------------------------- /python/images/list-neg-indexing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/list-neg-indexing.png -------------------------------------------------------------------------------- /pandas/data/grades-2.csv: -------------------------------------------------------------------------------- 1 | ,math,calculus,sport 2 | sara,88.0,79,92 3 | sophia,why?,99,89 4 | john,75.0,81,87 5 | ann,82.0,87,98 6 | -------------------------------------------------------------------------------- /python/images/comparison-operators.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/comparison-operators.png -------------------------------------------------------------------------------- /python/images/dictionary-example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/dictionary-example2.png -------------------------------------------------------------------------------- /python/images/dictionary-example3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/dictionary-example3.png -------------------------------------------------------------------------------- /python/images/inheritance-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/inheritance-example.png -------------------------------------------------------------------------------- /pandas/grades.csv: -------------------------------------------------------------------------------- 1 | ,math,sport,art,farsi 2 | sara,20,nan,19,20 3 | hoda,15,20.0,18,18 4 | hasan,15,20.0,18,19 5 | howsam,20,20.0,18,18 6 | -------------------------------------------------------------------------------- /python/lectures/section-0-intro-python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/lectures/section-0-intro-python.pdf -------------------------------------------------------------------------------- /python/images/comparison-operators-numpy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/images/comparison-operators-numpy.png -------------------------------------------------------------------------------- /python/lectures/section-0.5-intro-flowchart.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/python-for-ai/HEAD/python/lectures/section-0.5-intro-flowchart.pdf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | pandas/pandas-draft.ipynb 3 | /pandas/tmp 4 | /matplotlib/.ipynb_checkpoints 5 | /numpy/.ipynb_checkpoints 6 | /pandas/.ipynb_checkpoints 7 | /python/lectures/.ipynb_checkpoints 8 | /python/lectures/.ipynb_checkpoints 9 | /python/lectures/.ipynb_checkpoints 10 | /python/lectures/.ipynb_checkpoints 11 | /python/templates/.ipynb_checkpoints 12 | /python/lectures/.ipynb_checkpoints 13 | python/lectures/.ipynb_checkpoints/section-2-operators-checkpoint.ipynb 14 | -------------------------------------------------------------------------------- /python/lectures/.ipynb_checkpoints/section-1-variable-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7b931a7e-c38d-4acb-bead-7ae323e86100", 6 | "metadata": { 7 | "id": "deV1IkmrWtk5", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 1: Variables ⏰**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "b9a21ada-d0a4-4c9b-8594-53bcca1a1697", 17 | "metadata": { 18 | "jp-MarkdownHeadingCollapsed": true, 19 | "tags": [], 20 | "toc-hr-collapsed": true 21 | }, 22 | "source": [ 23 | "## **🔸 How to define a variable**" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "id": "13a42b73-819f-4461-b9f2-2a6b7309753c", 29 | "metadata": { 30 | "jp-MarkdownHeadingCollapsed": true, 31 | "tags": [] 32 | }, 33 | "source": [ 34 | "### int" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "id": "3ac877f3-a2eb-4ef8-8f46-d8e0e6cc4f52", 41 | "metadata": { 42 | "colab": { 43 | "base_uri": "https://localhost:8080/" 44 | }, 45 | "id": "-xctv3yQo95I", 46 | "outputId": "af38427a-57dc-432f-9d46-82c4b2951672" 47 | }, 48 | "outputs": [], 49 | "source": [] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "id": "c1d71ff8-a90a-4b20-8953-1869c3458adb", 54 | "metadata": { 55 | "jp-MarkdownHeadingCollapsed": true, 56 | "tags": [] 57 | }, 58 | "source": [ 59 | "### float" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": null, 65 | "id": "2fe07603-6045-4b1b-a097-5308295bf1d6", 66 | "metadata": { 67 | "colab": { 68 | "base_uri": "https://localhost:8080/" 69 | }, 70 | "id": "8oWEyE-KpPe7", 71 | "outputId": "ef707c83-fbf8-49a1-e661-c4a428c445e4" 72 | }, 73 | "outputs": [], 74 | "source": [] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "id": "3862a672-62d5-4d8c-85b1-35be7be68fbb", 79 | "metadata": { 80 | "jp-MarkdownHeadingCollapsed": true, 81 | "tags": [] 82 | }, 83 | "source": [ 84 | "### bool" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "id": "c58e23bd-8646-418f-b5c7-9e6b071a0df5", 91 | "metadata": { 92 | "colab": { 93 | "base_uri": "https://localhost:8080/" 94 | }, 95 | "id": "YRJ_OEFzpX7t", 96 | "outputId": "1494ccb1-fc7a-4a5f-b3aa-bb59b6a5adf0" 97 | }, 98 | "outputs": [], 99 | "source": [] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "id": "f3527ba5-a678-48f2-9027-96e7bdfcf5ac", 104 | "metadata": { 105 | "jp-MarkdownHeadingCollapsed": true, 106 | "tags": [] 107 | }, 108 | "source": [ 109 | "### string" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "id": "96417ba5-2ae1-4524-ada5-b95ecaa7ec46", 116 | "metadata": { 117 | "colab": { 118 | "base_uri": "https://localhost:8080/" 119 | }, 120 | "id": "Z03rWdh3phr8", 121 | "outputId": "a8f9cb3b-49a0-4339-b546-be9fff01db20" 122 | }, 123 | "outputs": [], 124 | "source": [] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "id": "3bdabf0f-6a83-4e70-aa20-a169c903f26a", 129 | "metadata": { 130 | "jp-MarkdownHeadingCollapsed": true, 131 | "tags": [], 132 | "toc-hr-collapsed": true 133 | }, 134 | "source": [ 135 | "## **🔸 Variable rules**" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "id": "b949e6a7-8266-4153-9867-8dc14a3d5b0b", 141 | "metadata": {}, 142 | "source": [ 143 | "\"string" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "id": "908a2a27-500a-494d-bbef-d788d8120658", 149 | "metadata": { 150 | "jp-MarkdownHeadingCollapsed": true, 151 | "tags": [] 152 | }, 153 | "source": [ 154 | "### Forbidden names 🚫" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "id": "d82cc8b3-55ee-4f8f-80fa-af7f9ca81c16", 161 | "metadata": {}, 162 | "outputs": [], 163 | "source": [] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "id": "9bc5df65-7db0-4c07-ac85-b4cbfabbeb69", 168 | "metadata": { 169 | "jp-MarkdownHeadingCollapsed": true, 170 | "tags": [] 171 | }, 172 | "source": [ 173 | "## **🔸 Type of a variable**" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "id": "ab2bbfa8-1160-4d0c-8145-023cd4e2c208", 179 | "metadata": {}, 180 | "source": [ 181 | "\"string" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": null, 187 | "id": "2873afd4-08dd-491b-95ea-5682b4489a82", 188 | "metadata": {}, 189 | "outputs": [], 190 | "source": [] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "id": "59e081ac-63a1-4ae2-af8c-da977116c5da", 195 | "metadata": { 196 | "jp-MarkdownHeadingCollapsed": true, 197 | "tags": [] 198 | }, 199 | "source": [ 200 | "## **🔸 Variable as an object**" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": null, 206 | "id": "49b08db6-4bcb-46af-9e88-760893baea15", 207 | "metadata": {}, 208 | "outputs": [], 209 | "source": [] 210 | } 211 | ], 212 | "metadata": { 213 | "kernelspec": { 214 | "display_name": "Python 3 (ipykernel)", 215 | "language": "python", 216 | "name": "python3" 217 | }, 218 | "language_info": { 219 | "codemirror_mode": { 220 | "name": "ipython", 221 | "version": 3 222 | }, 223 | "file_extension": ".py", 224 | "mimetype": "text/x-python", 225 | "name": "python", 226 | "nbconvert_exporter": "python", 227 | "pygments_lexer": "ipython3", 228 | "version": "3.9.12" 229 | } 230 | }, 231 | "nbformat": 4, 232 | "nbformat_minor": 5 233 | } 234 | -------------------------------------------------------------------------------- /python/images/numpylogo_dark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /python/templates/section-1-variables.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7b931a7e-c38d-4acb-bead-7ae323e86100", 6 | "metadata": { 7 | "id": "deV1IkmrWtk5", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 1: Variables ⏰**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "a2f5c8b2-8818-45e7-a78d-c8525dff3270", 17 | "metadata": {}, 18 | "source": [ 19 | "\"string" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "b9a21ada-d0a4-4c9b-8594-53bcca1a1697", 25 | "metadata": { 26 | "jp-MarkdownHeadingCollapsed": true, 27 | "tags": [], 28 | "toc-hr-collapsed": true 29 | }, 30 | "source": [ 31 | "## **🔸 How to define a variable**" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "id": "13a42b73-819f-4461-b9f2-2a6b7309753c", 37 | "metadata": { 38 | "jp-MarkdownHeadingCollapsed": true, 39 | "tags": [] 40 | }, 41 | "source": [ 42 | "### int" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "id": "3ac877f3-a2eb-4ef8-8f46-d8e0e6cc4f52", 49 | "metadata": { 50 | "colab": { 51 | "base_uri": "https://localhost:8080/" 52 | }, 53 | "id": "-xctv3yQo95I", 54 | "outputId": "af38427a-57dc-432f-9d46-82c4b2951672" 55 | }, 56 | "outputs": [], 57 | "source": [] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "id": "c1d71ff8-a90a-4b20-8953-1869c3458adb", 62 | "metadata": { 63 | "jp-MarkdownHeadingCollapsed": true, 64 | "tags": [] 65 | }, 66 | "source": [ 67 | "### float" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "id": "2fe07603-6045-4b1b-a097-5308295bf1d6", 74 | "metadata": { 75 | "colab": { 76 | "base_uri": "https://localhost:8080/" 77 | }, 78 | "id": "8oWEyE-KpPe7", 79 | "outputId": "ef707c83-fbf8-49a1-e661-c4a428c445e4" 80 | }, 81 | "outputs": [], 82 | "source": [] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "id": "3862a672-62d5-4d8c-85b1-35be7be68fbb", 87 | "metadata": { 88 | "jp-MarkdownHeadingCollapsed": true, 89 | "tags": [] 90 | }, 91 | "source": [ 92 | "### bool" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "id": "c58e23bd-8646-418f-b5c7-9e6b071a0df5", 99 | "metadata": { 100 | "colab": { 101 | "base_uri": "https://localhost:8080/" 102 | }, 103 | "id": "YRJ_OEFzpX7t", 104 | "outputId": "1494ccb1-fc7a-4a5f-b3aa-bb59b6a5adf0" 105 | }, 106 | "outputs": [], 107 | "source": [] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "id": "f3527ba5-a678-48f2-9027-96e7bdfcf5ac", 112 | "metadata": { 113 | "jp-MarkdownHeadingCollapsed": true, 114 | "tags": [] 115 | }, 116 | "source": [ 117 | "### string" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "id": "96417ba5-2ae1-4524-ada5-b95ecaa7ec46", 124 | "metadata": { 125 | "colab": { 126 | "base_uri": "https://localhost:8080/" 127 | }, 128 | "id": "Z03rWdh3phr8", 129 | "outputId": "a8f9cb3b-49a0-4339-b546-be9fff01db20" 130 | }, 131 | "outputs": [], 132 | "source": [] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "id": "3bdabf0f-6a83-4e70-aa20-a169c903f26a", 137 | "metadata": { 138 | "jp-MarkdownHeadingCollapsed": true, 139 | "tags": [], 140 | "toc-hr-collapsed": true 141 | }, 142 | "source": [ 143 | "## **🔸 Variable rules**" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "id": "b949e6a7-8266-4153-9867-8dc14a3d5b0b", 149 | "metadata": {}, 150 | "source": [ 151 | "\"string" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "id": "a11aaba3-e3a2-49c8-8c18-564267df4366", 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "id": "908a2a27-500a-494d-bbef-d788d8120658", 165 | "metadata": { 166 | "jp-MarkdownHeadingCollapsed": true, 167 | "tags": [] 168 | }, 169 | "source": [ 170 | "### Forbidden names 🚫" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": null, 176 | "id": "d82cc8b3-55ee-4f8f-80fa-af7f9ca81c16", 177 | "metadata": {}, 178 | "outputs": [], 179 | "source": [] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": null, 184 | "id": "0b51a9e5-38c7-4512-a00b-4f6570aa9596", 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "id": "9bc5df65-7db0-4c07-ac85-b4cbfabbeb69", 192 | "metadata": { 193 | "jp-MarkdownHeadingCollapsed": true, 194 | "tags": [] 195 | }, 196 | "source": [ 197 | "## **🔸 Type of a variable**" 198 | ] 199 | }, 200 | { 201 | "cell_type": "markdown", 202 | "id": "ab2bbfa8-1160-4d0c-8145-023cd4e2c208", 203 | "metadata": {}, 204 | "source": [ 205 | "\"string" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": null, 211 | "id": "2873afd4-08dd-491b-95ea-5682b4489a82", 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "id": "7da895d7-fb12-4dee-8dac-84a4806e71d5", 219 | "metadata": { 220 | "jp-MarkdownHeadingCollapsed": true, 221 | "tags": [] 222 | }, 223 | "source": [ 224 | "### Type conversion" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": null, 230 | "id": "b88fc095-5cbb-4d6d-b200-ca5bd0d93009", 231 | "metadata": {}, 232 | "outputs": [], 233 | "source": [] 234 | }, 235 | { 236 | "cell_type": "markdown", 237 | "id": "59e081ac-63a1-4ae2-af8c-da977116c5da", 238 | "metadata": { 239 | "jp-MarkdownHeadingCollapsed": true, 240 | "tags": [] 241 | }, 242 | "source": [ 243 | "## **🔸 Variable as an object**" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": null, 249 | "id": "e7fb7982-54a7-4f75-bfbc-30811282c2dd", 250 | "metadata": {}, 251 | "outputs": [], 252 | "source": [] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": null, 257 | "id": "ae91f712-c32e-4a48-8ba4-8ec5c9ab18f5", 258 | "metadata": {}, 259 | "outputs": [], 260 | "source": [] 261 | }, 262 | { 263 | "cell_type": "markdown", 264 | "id": "00df43e9-58b9-42b5-ad4c-267d0d4de157", 265 | "metadata": { 266 | "jp-MarkdownHeadingCollapsed": true, 267 | "tags": [] 268 | }, 269 | "source": [ 270 | "## **🔸 Style guide**" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": null, 276 | "id": "49b08db6-4bcb-46af-9e88-760893baea15", 277 | "metadata": {}, 278 | "outputs": [], 279 | "source": [] 280 | } 281 | ], 282 | "metadata": { 283 | "kernelspec": { 284 | "display_name": "Python 3 (ipykernel)", 285 | "language": "python", 286 | "name": "python3" 287 | }, 288 | "language_info": { 289 | "codemirror_mode": { 290 | "name": "ipython", 291 | "version": 3 292 | }, 293 | "file_extension": ".py", 294 | "mimetype": "text/x-python", 295 | "name": "python", 296 | "nbconvert_exporter": "python", 297 | "pygments_lexer": "ipython3", 298 | "version": "3.9.15" 299 | } 300 | }, 301 | "nbformat": 4, 302 | "nbformat_minor": 5 303 | } 304 | -------------------------------------------------------------------------------- /python/lectures/section-1-variables.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7b931a7e-c38d-4acb-bead-7ae323e86100", 6 | "metadata": { 7 | "id": "deV1IkmrWtk5", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 1: Variables ⏰**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "a2f5c8b2-8818-45e7-a78d-c8525dff3270", 17 | "metadata": {}, 18 | "source": [ 19 | "\"string" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "b9a21ada-d0a4-4c9b-8594-53bcca1a1697", 25 | "metadata": { 26 | "tags": [], 27 | "toc-hr-collapsed": true 28 | }, 29 | "source": [ 30 | "## **🔸 How to define a variable**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "id": "13a42b73-819f-4461-b9f2-2a6b7309753c", 36 | "metadata": { 37 | "tags": [] 38 | }, 39 | "source": [ 40 | "### int" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 64, 46 | "id": "3ac877f3-a2eb-4ef8-8f46-d8e0e6cc4f52", 47 | "metadata": { 48 | "colab": { 49 | "base_uri": "https://localhost:8080/" 50 | }, 51 | "id": "-xctv3yQo95I", 52 | "outputId": "af38427a-57dc-432f-9d46-82c4b2951672" 53 | }, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "3\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "x = 3\n", 65 | "print(x)\n", 66 | "# x\n", 67 | "y = 3" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "id": "c1d71ff8-a90a-4b20-8953-1869c3458adb", 73 | "metadata": { 74 | "tags": [] 75 | }, 76 | "source": [ 77 | "### float" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 66, 83 | "id": "2fe07603-6045-4b1b-a097-5308295bf1d6", 84 | "metadata": { 85 | "colab": { 86 | "base_uri": "https://localhost:8080/" 87 | }, 88 | "id": "8oWEyE-KpPe7", 89 | "outputId": "ef707c83-fbf8-49a1-e661-c4a428c445e4" 90 | }, 91 | "outputs": [ 92 | { 93 | "data": { 94 | "text/plain": [ 95 | "3.0" 96 | ] 97 | }, 98 | "execution_count": 66, 99 | "metadata": {}, 100 | "output_type": "execute_result" 101 | } 102 | ], 103 | "source": [ 104 | "y = 3.\n", 105 | "y" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "id": "3862a672-62d5-4d8c-85b1-35be7be68fbb", 111 | "metadata": { 112 | "tags": [] 113 | }, 114 | "source": [ 115 | "### bool" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 69, 121 | "id": "c58e23bd-8646-418f-b5c7-9e6b071a0df5", 122 | "metadata": { 123 | "colab": { 124 | "base_uri": "https://localhost:8080/" 125 | }, 126 | "id": "YRJ_OEFzpX7t", 127 | "outputId": "1494ccb1-fc7a-4a5f-b3aa-bb59b6a5adf0" 128 | }, 129 | "outputs": [ 130 | { 131 | "data": { 132 | "text/plain": [ 133 | "False" 134 | ] 135 | }, 136 | "execution_count": 69, 137 | "metadata": {}, 138 | "output_type": "execute_result" 139 | } 140 | ], 141 | "source": [ 142 | "w = True\n", 143 | "w = False\n", 144 | "w" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "id": "f3527ba5-a678-48f2-9027-96e7bdfcf5ac", 150 | "metadata": { 151 | "tags": [] 152 | }, 153 | "source": [ 154 | "### string" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 72, 160 | "id": "96417ba5-2ae1-4524-ada5-b95ecaa7ec46", 161 | "metadata": { 162 | "colab": { 163 | "base_uri": "https://localhost:8080/" 164 | }, 165 | "id": "Z03rWdh3phr8", 166 | "outputId": "a8f9cb3b-49a0-4339-b546-be9fff01db20" 167 | }, 168 | "outputs": [ 169 | { 170 | "data": { 171 | "text/plain": [ 172 | "'salam howsam!'" 173 | ] 174 | }, 175 | "execution_count": 72, 176 | "metadata": {}, 177 | "output_type": "execute_result" 178 | } 179 | ], 180 | "source": [ 181 | "z = 'salam howsam!'\n", 182 | "z = \"salam howsam!\"\n", 183 | "z" 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "id": "3bdabf0f-6a83-4e70-aa20-a169c903f26a", 189 | "metadata": { 190 | "tags": [], 191 | "toc-hr-collapsed": true 192 | }, 193 | "source": [ 194 | "## **🔸 Variable rules**" 195 | ] 196 | }, 197 | { 198 | "cell_type": "markdown", 199 | "id": "b949e6a7-8266-4153-9867-8dc14a3d5b0b", 200 | "metadata": {}, 201 | "source": [ 202 | "\"string" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 77, 208 | "id": "a11aaba3-e3a2-49c8-8c18-564267df4366", 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "name": "stdout", 213 | "output_type": "stream", 214 | "text": [ 215 | "3 0.5\n" 216 | ] 217 | } 218 | ], 219 | "source": [ 220 | "_a = 3\n", 221 | "\n", 222 | "# 3a = 4\n", 223 | "\n", 224 | "# a@ = 4\n", 225 | "\n", 226 | "a = 3\n", 227 | "A = .5\n", 228 | "print(a, A)\n", 229 | "\n", 230 | "a_kjhsd_2 = 2" 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "id": "908a2a27-500a-494d-bbef-d788d8120658", 236 | "metadata": { 237 | "tags": [] 238 | }, 239 | "source": [ 240 | "### Forbidden names 🚫" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 78, 246 | "id": "d82cc8b3-55ee-4f8f-80fa-af7f9ca81c16", 247 | "metadata": {}, 248 | "outputs": [ 249 | { 250 | "name": "stdout", 251 | "output_type": "stream", 252 | "text": [ 253 | "\n", 254 | "Here is a list of the Python keywords. Enter any keyword to get more help.\n", 255 | "\n", 256 | "False break for not\n", 257 | "None class from or\n", 258 | "True continue global pass\n", 259 | "__peg_parser__ def if raise\n", 260 | "and del import return\n", 261 | "as elif in try\n", 262 | "assert else is while\n", 263 | "async except lambda with\n", 264 | "await finally nonlocal yield\n", 265 | "\n" 266 | ] 267 | } 268 | ], 269 | "source": [ 270 | "help('keywords')" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": 80, 276 | "id": "0b51a9e5-38c7-4512-a00b-4f6570aa9596", 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "ename": "SyntaxError", 281 | "evalue": "invalid syntax (2027491807.py, line 3)", 282 | "output_type": "error", 283 | "traceback": [ 284 | "\u001b[1;36m Input \u001b[1;32mIn [80]\u001b[1;36m\u001b[0m\n\u001b[1;33m for = 4\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 285 | ] 286 | } 287 | ], 288 | "source": [ 289 | "# True = 4\n", 290 | "\n", 291 | "for = 4" 292 | ] 293 | }, 294 | { 295 | "cell_type": "markdown", 296 | "id": "9bc5df65-7db0-4c07-ac85-b4cbfabbeb69", 297 | "metadata": { 298 | "tags": [] 299 | }, 300 | "source": [ 301 | "## **🔸 Type of a variable**" 302 | ] 303 | }, 304 | { 305 | "cell_type": "markdown", 306 | "id": "ab2bbfa8-1160-4d0c-8145-023cd4e2c208", 307 | "metadata": {}, 308 | "source": [ 309 | "\"string" 310 | ] 311 | }, 312 | { 313 | "cell_type": "code", 314 | "execution_count": 84, 315 | "id": "2873afd4-08dd-491b-95ea-5682b4489a82", 316 | "metadata": {}, 317 | "outputs": [ 318 | { 319 | "data": { 320 | "text/plain": [ 321 | "(int, float, str, bool)" 322 | ] 323 | }, 324 | "execution_count": 84, 325 | "metadata": {}, 326 | "output_type": "execute_result" 327 | } 328 | ], 329 | "source": [ 330 | "type(x), type(y), type(z), type(w)" 331 | ] 332 | }, 333 | { 334 | "cell_type": "markdown", 335 | "id": "7da895d7-fb12-4dee-8dac-84a4806e71d5", 336 | "metadata": { 337 | "tags": [] 338 | }, 339 | "source": [ 340 | "### Type conversion" 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": 32, 346 | "id": "b88fc095-5cbb-4d6d-b200-ca5bd0d93009", 347 | "metadata": {}, 348 | "outputs": [ 349 | { 350 | "name": "stdout", 351 | "output_type": "stream", 352 | "text": [ 353 | " \n", 354 | "3 \n", 355 | "3.0 \n", 356 | "3.1 \n", 357 | "3 \n", 358 | "3.1 \n", 359 | "3.1 \n", 360 | "0 \n", 361 | "False \n" 362 | ] 363 | }, 364 | { 365 | "data": { 366 | "text/plain": [ 367 | "False" 368 | ] 369 | }, 370 | "execution_count": 32, 371 | "metadata": {}, 372 | "output_type": "execute_result" 373 | } 374 | ], 375 | "source": [ 376 | "print(int, float, str, bool)\n", 377 | "\n", 378 | "a = 3\n", 379 | "print(a, type(a))\n", 380 | "a = float(a)\n", 381 | "print(a, type(a))\n", 382 | "\n", 383 | "a = 3.1\n", 384 | "print(a, type(a))\n", 385 | "a = int(a)\n", 386 | "print(a, type(a))\n", 387 | "\n", 388 | "a = 3.1\n", 389 | "print(a, type(a))\n", 390 | "a = str(a)\n", 391 | "print(a, type(a))\n", 392 | "a\n", 393 | "\n", 394 | "a = 0\n", 395 | "print(a, type(a))\n", 396 | "a = bool(a)\n", 397 | "print(a, type(a))\n", 398 | "\n", 399 | "a = float()\n", 400 | "a\n", 401 | "\n", 402 | "a = int()\n", 403 | "a\n", 404 | "\n", 405 | "a = str()\n", 406 | "a\n", 407 | "\n", 408 | "a = bool()\n", 409 | "a" 410 | ] 411 | }, 412 | { 413 | "cell_type": "markdown", 414 | "id": "59e081ac-63a1-4ae2-af8c-da977116c5da", 415 | "metadata": { 416 | "tags": [] 417 | }, 418 | "source": [ 419 | "## **🔸 Variable as an object**" 420 | ] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": 87, 425 | "id": "e7fb7982-54a7-4f75-bfbc-30811282c2dd", 426 | "metadata": {}, 427 | "outputs": [ 428 | { 429 | "data": { 430 | "text/plain": [ 431 | "(int, float)" 432 | ] 433 | }, 434 | "execution_count": 87, 435 | "metadata": {}, 436 | "output_type": "execute_result" 437 | } 438 | ], 439 | "source": [ 440 | "x.__class__, y.__class__" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 90, 446 | "id": "ae91f712-c32e-4a48-8ba4-8ec5c9ab18f5", 447 | "metadata": {}, 448 | "outputs": [ 449 | { 450 | "data": { 451 | "text/plain": [ 452 | "('salam howsam!', 'SALAM HOWSAM!')" 453 | ] 454 | }, 455 | "execution_count": 90, 456 | "metadata": {}, 457 | "output_type": "execute_result" 458 | } 459 | ], 460 | "source": [ 461 | "z.__class__\n", 462 | "z, z.upper()" 463 | ] 464 | }, 465 | { 466 | "cell_type": "markdown", 467 | "id": "00df43e9-58b9-42b5-ad4c-267d0d4de157", 468 | "metadata": { 469 | "tags": [] 470 | }, 471 | "source": [ 472 | "## **🔸 Style guide**" 473 | ] 474 | }, 475 | { 476 | "cell_type": "code", 477 | "execution_count": null, 478 | "id": "49b08db6-4bcb-46af-9e88-760893baea15", 479 | "metadata": {}, 480 | "outputs": [], 481 | "source": [ 482 | "pi = 3.14\n", 483 | "\n", 484 | "area_circle = 53.2\n", 485 | "# AreaCircle = 53.4\n", 486 | "\n", 487 | "pi2 = 3.14" 488 | ] 489 | } 490 | ], 491 | "metadata": { 492 | "kernelspec": { 493 | "display_name": "Python 3 (ipykernel)", 494 | "language": "python", 495 | "name": "python3" 496 | }, 497 | "language_info": { 498 | "codemirror_mode": { 499 | "name": "ipython", 500 | "version": 3 501 | }, 502 | "file_extension": ".py", 503 | "mimetype": "text/x-python", 504 | "name": "python", 505 | "nbconvert_exporter": "python", 506 | "pygments_lexer": "ipython3", 507 | "version": "3.9.15" 508 | } 509 | }, 510 | "nbformat": 4, 511 | "nbformat_minor": 5 512 | } 513 | -------------------------------------------------------------------------------- /python/lectures/.ipynb_checkpoints/section-1-variables-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7b931a7e-c38d-4acb-bead-7ae323e86100", 6 | "metadata": { 7 | "id": "deV1IkmrWtk5", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 1: Variables ⏰**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "a2f5c8b2-8818-45e7-a78d-c8525dff3270", 17 | "metadata": {}, 18 | "source": [ 19 | "\"string" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "b9a21ada-d0a4-4c9b-8594-53bcca1a1697", 25 | "metadata": { 26 | "jp-MarkdownHeadingCollapsed": true, 27 | "tags": [], 28 | "toc-hr-collapsed": true 29 | }, 30 | "source": [ 31 | "## **🔸 How to define a variable**" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "id": "13a42b73-819f-4461-b9f2-2a6b7309753c", 37 | "metadata": { 38 | "tags": [] 39 | }, 40 | "source": [ 41 | "### int" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 64, 47 | "id": "3ac877f3-a2eb-4ef8-8f46-d8e0e6cc4f52", 48 | "metadata": { 49 | "colab": { 50 | "base_uri": "https://localhost:8080/" 51 | }, 52 | "id": "-xctv3yQo95I", 53 | "outputId": "af38427a-57dc-432f-9d46-82c4b2951672" 54 | }, 55 | "outputs": [ 56 | { 57 | "name": "stdout", 58 | "output_type": "stream", 59 | "text": [ 60 | "3\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "x = 3\n", 66 | "print(x)\n", 67 | "# x\n", 68 | "y = 3" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "id": "c1d71ff8-a90a-4b20-8953-1869c3458adb", 74 | "metadata": { 75 | "tags": [] 76 | }, 77 | "source": [ 78 | "### float" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 66, 84 | "id": "2fe07603-6045-4b1b-a097-5308295bf1d6", 85 | "metadata": { 86 | "colab": { 87 | "base_uri": "https://localhost:8080/" 88 | }, 89 | "id": "8oWEyE-KpPe7", 90 | "outputId": "ef707c83-fbf8-49a1-e661-c4a428c445e4" 91 | }, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "3.0" 97 | ] 98 | }, 99 | "execution_count": 66, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "y = 3.\n", 106 | "y" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "id": "3862a672-62d5-4d8c-85b1-35be7be68fbb", 112 | "metadata": { 113 | "tags": [] 114 | }, 115 | "source": [ 116 | "### bool" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 69, 122 | "id": "c58e23bd-8646-418f-b5c7-9e6b071a0df5", 123 | "metadata": { 124 | "colab": { 125 | "base_uri": "https://localhost:8080/" 126 | }, 127 | "id": "YRJ_OEFzpX7t", 128 | "outputId": "1494ccb1-fc7a-4a5f-b3aa-bb59b6a5adf0" 129 | }, 130 | "outputs": [ 131 | { 132 | "data": { 133 | "text/plain": [ 134 | "False" 135 | ] 136 | }, 137 | "execution_count": 69, 138 | "metadata": {}, 139 | "output_type": "execute_result" 140 | } 141 | ], 142 | "source": [ 143 | "w = True\n", 144 | "w = False\n", 145 | "w" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "id": "f3527ba5-a678-48f2-9027-96e7bdfcf5ac", 151 | "metadata": { 152 | "tags": [] 153 | }, 154 | "source": [ 155 | "### string" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 72, 161 | "id": "96417ba5-2ae1-4524-ada5-b95ecaa7ec46", 162 | "metadata": { 163 | "colab": { 164 | "base_uri": "https://localhost:8080/" 165 | }, 166 | "id": "Z03rWdh3phr8", 167 | "outputId": "a8f9cb3b-49a0-4339-b546-be9fff01db20" 168 | }, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "'salam howsam!'" 174 | ] 175 | }, 176 | "execution_count": 72, 177 | "metadata": {}, 178 | "output_type": "execute_result" 179 | } 180 | ], 181 | "source": [ 182 | "z = 'salam howsam!'\n", 183 | "z = \"salam howsam!\"\n", 184 | "z" 185 | ] 186 | }, 187 | { 188 | "cell_type": "markdown", 189 | "id": "3bdabf0f-6a83-4e70-aa20-a169c903f26a", 190 | "metadata": { 191 | "jp-MarkdownHeadingCollapsed": true, 192 | "tags": [], 193 | "toc-hr-collapsed": true 194 | }, 195 | "source": [ 196 | "## **🔸 Variable rules**" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "id": "b949e6a7-8266-4153-9867-8dc14a3d5b0b", 202 | "metadata": {}, 203 | "source": [ 204 | "\"string" 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 77, 210 | "id": "a11aaba3-e3a2-49c8-8c18-564267df4366", 211 | "metadata": {}, 212 | "outputs": [ 213 | { 214 | "name": "stdout", 215 | "output_type": "stream", 216 | "text": [ 217 | "3 0.5\n" 218 | ] 219 | } 220 | ], 221 | "source": [ 222 | "_a = 3\n", 223 | "\n", 224 | "# 3a = 4\n", 225 | "\n", 226 | "# a@ = 4\n", 227 | "\n", 228 | "a = 3\n", 229 | "A = .5\n", 230 | "print(a, A)\n", 231 | "\n", 232 | "a_kjhsd_2 = 2" 233 | ] 234 | }, 235 | { 236 | "cell_type": "markdown", 237 | "id": "908a2a27-500a-494d-bbef-d788d8120658", 238 | "metadata": { 239 | "tags": [] 240 | }, 241 | "source": [ 242 | "### Forbidden names 🚫" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 78, 248 | "id": "d82cc8b3-55ee-4f8f-80fa-af7f9ca81c16", 249 | "metadata": {}, 250 | "outputs": [ 251 | { 252 | "name": "stdout", 253 | "output_type": "stream", 254 | "text": [ 255 | "\n", 256 | "Here is a list of the Python keywords. Enter any keyword to get more help.\n", 257 | "\n", 258 | "False break for not\n", 259 | "None class from or\n", 260 | "True continue global pass\n", 261 | "__peg_parser__ def if raise\n", 262 | "and del import return\n", 263 | "as elif in try\n", 264 | "assert else is while\n", 265 | "async except lambda with\n", 266 | "await finally nonlocal yield\n", 267 | "\n" 268 | ] 269 | } 270 | ], 271 | "source": [ 272 | "help('keywords')" 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": 80, 278 | "id": "0b51a9e5-38c7-4512-a00b-4f6570aa9596", 279 | "metadata": {}, 280 | "outputs": [ 281 | { 282 | "ename": "SyntaxError", 283 | "evalue": "invalid syntax (2027491807.py, line 3)", 284 | "output_type": "error", 285 | "traceback": [ 286 | "\u001b[1;36m Input \u001b[1;32mIn [80]\u001b[1;36m\u001b[0m\n\u001b[1;33m for = 4\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 287 | ] 288 | } 289 | ], 290 | "source": [ 291 | "# True = 4\n", 292 | "\n", 293 | "for = 4" 294 | ] 295 | }, 296 | { 297 | "cell_type": "markdown", 298 | "id": "9bc5df65-7db0-4c07-ac85-b4cbfabbeb69", 299 | "metadata": { 300 | "tags": [] 301 | }, 302 | "source": [ 303 | "## **🔸 Type of a variable**" 304 | ] 305 | }, 306 | { 307 | "cell_type": "markdown", 308 | "id": "ab2bbfa8-1160-4d0c-8145-023cd4e2c208", 309 | "metadata": {}, 310 | "source": [ 311 | "\"string" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 84, 317 | "id": "2873afd4-08dd-491b-95ea-5682b4489a82", 318 | "metadata": {}, 319 | "outputs": [ 320 | { 321 | "data": { 322 | "text/plain": [ 323 | "(int, float, str, bool)" 324 | ] 325 | }, 326 | "execution_count": 84, 327 | "metadata": {}, 328 | "output_type": "execute_result" 329 | } 330 | ], 331 | "source": [ 332 | "type(x), type(y), type(z), type(w)" 333 | ] 334 | }, 335 | { 336 | "cell_type": "markdown", 337 | "id": "7da895d7-fb12-4dee-8dac-84a4806e71d5", 338 | "metadata": { 339 | "jp-MarkdownHeadingCollapsed": true, 340 | "tags": [] 341 | }, 342 | "source": [ 343 | "### Type conversion" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 32, 349 | "id": "b88fc095-5cbb-4d6d-b200-ca5bd0d93009", 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "name": "stdout", 354 | "output_type": "stream", 355 | "text": [ 356 | " \n", 357 | "3 \n", 358 | "3.0 \n", 359 | "3.1 \n", 360 | "3 \n", 361 | "3.1 \n", 362 | "3.1 \n", 363 | "0 \n", 364 | "False \n" 365 | ] 366 | }, 367 | { 368 | "data": { 369 | "text/plain": [ 370 | "False" 371 | ] 372 | }, 373 | "execution_count": 32, 374 | "metadata": {}, 375 | "output_type": "execute_result" 376 | } 377 | ], 378 | "source": [ 379 | "print(int, float, str, bool)\n", 380 | "\n", 381 | "a = 3\n", 382 | "print(a, type(a))\n", 383 | "a = float(a)\n", 384 | "print(a, type(a))\n", 385 | "\n", 386 | "a = 3.1\n", 387 | "print(a, type(a))\n", 388 | "a = int(a)\n", 389 | "print(a, type(a))\n", 390 | "\n", 391 | "a = 3.1\n", 392 | "print(a, type(a))\n", 393 | "a = str(a)\n", 394 | "print(a, type(a))\n", 395 | "a\n", 396 | "\n", 397 | "a = 0\n", 398 | "print(a, type(a))\n", 399 | "a = bool(a)\n", 400 | "print(a, type(a))\n", 401 | "\n", 402 | "a = float()\n", 403 | "a\n", 404 | "\n", 405 | "a = int()\n", 406 | "a\n", 407 | "\n", 408 | "a = str()\n", 409 | "a\n", 410 | "\n", 411 | "a = bool()\n", 412 | "a" 413 | ] 414 | }, 415 | { 416 | "cell_type": "markdown", 417 | "id": "59e081ac-63a1-4ae2-af8c-da977116c5da", 418 | "metadata": { 419 | "jp-MarkdownHeadingCollapsed": true, 420 | "tags": [] 421 | }, 422 | "source": [ 423 | "## **🔸 Variable as an object**" 424 | ] 425 | }, 426 | { 427 | "cell_type": "code", 428 | "execution_count": 87, 429 | "id": "e7fb7982-54a7-4f75-bfbc-30811282c2dd", 430 | "metadata": {}, 431 | "outputs": [ 432 | { 433 | "data": { 434 | "text/plain": [ 435 | "(int, float)" 436 | ] 437 | }, 438 | "execution_count": 87, 439 | "metadata": {}, 440 | "output_type": "execute_result" 441 | } 442 | ], 443 | "source": [ 444 | "x.__class__, y.__class__" 445 | ] 446 | }, 447 | { 448 | "cell_type": "code", 449 | "execution_count": 90, 450 | "id": "ae91f712-c32e-4a48-8ba4-8ec5c9ab18f5", 451 | "metadata": {}, 452 | "outputs": [ 453 | { 454 | "data": { 455 | "text/plain": [ 456 | "('salam howsam!', 'SALAM HOWSAM!')" 457 | ] 458 | }, 459 | "execution_count": 90, 460 | "metadata": {}, 461 | "output_type": "execute_result" 462 | } 463 | ], 464 | "source": [ 465 | "z.__class__\n", 466 | "z, z.upper()" 467 | ] 468 | }, 469 | { 470 | "cell_type": "markdown", 471 | "id": "00df43e9-58b9-42b5-ad4c-267d0d4de157", 472 | "metadata": { 473 | "jp-MarkdownHeadingCollapsed": true, 474 | "tags": [] 475 | }, 476 | "source": [ 477 | "## **🔸 Style guide**" 478 | ] 479 | }, 480 | { 481 | "cell_type": "code", 482 | "execution_count": null, 483 | "id": "49b08db6-4bcb-46af-9e88-760893baea15", 484 | "metadata": {}, 485 | "outputs": [], 486 | "source": [ 487 | "pi = 3.14\n", 488 | "\n", 489 | "area_circle = 53.2\n", 490 | "# AreaCircle = 53.4\n", 491 | "\n", 492 | "pi2 = 3.14" 493 | ] 494 | } 495 | ], 496 | "metadata": { 497 | "kernelspec": { 498 | "display_name": "Python 3 (ipykernel)", 499 | "language": "python", 500 | "name": "python3" 501 | }, 502 | "language_info": { 503 | "codemirror_mode": { 504 | "name": "ipython", 505 | "version": 3 506 | }, 507 | "file_extension": ".py", 508 | "mimetype": "text/x-python", 509 | "name": "python", 510 | "nbconvert_exporter": "python", 511 | "pygments_lexer": "ipython3", 512 | "version": "3.9.12" 513 | } 514 | }, 515 | "nbformat": 4, 516 | "nbformat_minor": 5 517 | } 518 | -------------------------------------------------------------------------------- /python/templates/section-4-comparison.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f18ece75-eec3-40b1-9af8-355087006bb4", 6 | "metadata": { 7 | "id": "PB9MOYPq50Wx", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 4: Comparison and Logical Operators 🐏**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "1bbcdf12-354f-4554-a329-486f4ed4bc68", 17 | "metadata": {}, 18 | "source": [ 19 | "\"string" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "70bb3145-2a25-4fac-8f5b-1141119323a8", 25 | "metadata": { 26 | "id": "A9c3D-3n61Du", 27 | "jp-MarkdownHeadingCollapsed": true, 28 | "tags": [] 29 | }, 30 | "source": [ 31 | "## 🔸 **Logical operators**" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "id": "ab68c888-a639-4ae5-aeea-d89f8f1e613e", 37 | "metadata": {}, 38 | "source": [ 39 | "\"string" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 49, 45 | "id": "f76d615e-5f24-4c40-adb3-3b7a23c536ec", 46 | "metadata": { 47 | "colab": { 48 | "base_uri": "https://localhost:8080/" 49 | }, 50 | "id": "1NZQwcpJ-ffr", 51 | "outputId": "6a4ac375-079e-4afe-f871-b87906c30913" 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "a = True\n", 56 | "b = False\n", 57 | "c = True" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "id": "288a5bea-90c3-424d-8aa0-5b9bbf41f733", 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "id": "9459903c-5ce3-4b62-a62c-ff022bca0eb6", 72 | "metadata": {}, 73 | "outputs": [], 74 | "source": [] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "id": "344d32e1-af11-479b-8316-5a174f308763", 79 | "metadata": { 80 | "jp-MarkdownHeadingCollapsed": true, 81 | "tags": [] 82 | }, 83 | "source": [ 84 | "## 🔸 **Comparison operators**" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 55, 90 | "id": "aa688056-d186-4ed2-ae39-f3f9ac6489a8", 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "a = True\n", 95 | "b = False\n", 96 | "\n", 97 | "c = 3.4\n", 98 | "d = 6\n", 99 | "e = 6.\n", 100 | "\n", 101 | "f = 'a'\n", 102 | "g = 'A'\n", 103 | "h = 'a'" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "id": "5661d3ee-ec91-423a-879c-a44bb5a75c6a", 109 | "metadata": {}, 110 | "source": [ 111 | "\"string" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "id": "7b621b52-7a50-4dbb-9099-bf1ebf777bd9", 117 | "metadata": { 118 | "jp-MarkdownHeadingCollapsed": true, 119 | "tags": [] 120 | }, 121 | "source": [ 122 | "### == & !=" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "id": "6e6881f7-d998-4480-83d2-c3405f1d1db3", 129 | "metadata": { 130 | "colab": { 131 | "base_uri": "https://localhost:8080/" 132 | }, 133 | "id": "p2kobWHG6-rP", 134 | "outputId": "5745ff26-0cac-490d-d319-695cad2ba12e" 135 | }, 136 | "outputs": [], 137 | "source": [] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": null, 142 | "id": "82c97876-00e9-4177-8976-98af26529ed2", 143 | "metadata": { 144 | "colab": { 145 | "base_uri": "https://localhost:8080/" 146 | }, 147 | "id": "zDN5Oe-n80EU", 148 | "outputId": "f276408f-ec05-4614-eb10-e90e1ea3c93e" 149 | }, 150 | "outputs": [], 151 | "source": [] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "id": "7361e201-d4ba-49f1-abc6-c022c811d117", 156 | "metadata": { 157 | "jp-MarkdownHeadingCollapsed": true, 158 | "tags": [] 159 | }, 160 | "source": [ 161 | "### > & <" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": null, 167 | "id": "ea7b119f-a827-422d-bb2c-86be27f139b6", 168 | "metadata": { 169 | "colab": { 170 | "base_uri": "https://localhost:8080/" 171 | }, 172 | "id": "A14-T6zV9oFK", 173 | "outputId": "811cda0b-e94b-48c5-8cd9-a31963a275cd" 174 | }, 175 | "outputs": [], 176 | "source": [] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": null, 181 | "id": "44ec2db3-8971-4aa5-be9b-2178ca1c0abd", 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "id": "dffb314a-4972-4acb-b5ad-3bebaaea68f2", 189 | "metadata": { 190 | "jp-MarkdownHeadingCollapsed": true, 191 | "tags": [] 192 | }, 193 | "source": [ 194 | "### Comparison in list" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": null, 200 | "id": "3f909d67-f9dd-4f8b-8df4-4d6c34c0a4d9", 201 | "metadata": {}, 202 | "outputs": [], 203 | "source": [] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "id": "7ec0f763-dbb4-4c2a-92ab-e6f5920a75cf", 208 | "metadata": { 209 | "jp-MarkdownHeadingCollapsed": true, 210 | "tags": [] 211 | }, 212 | "source": [ 213 | "### Comparison for floating-point numbers" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": null, 219 | "id": "755da3ec-4760-4e93-bad5-6c788fc7f44f", 220 | "metadata": {}, 221 | "outputs": [], 222 | "source": [] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": null, 227 | "id": "2ef11c0f-8e95-4723-8c74-fd284d4a7214", 228 | "metadata": {}, 229 | "outputs": [], 230 | "source": [] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": null, 235 | "id": "4d6566aa-df54-4cac-ac01-eeca08e3db4a", 236 | "metadata": {}, 237 | "outputs": [], 238 | "source": [] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "id": "323ad4df-444c-4232-b5c2-60e7f775ed51", 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [] 247 | }, 248 | { 249 | "cell_type": "markdown", 250 | "id": "fbc88b9d-e47b-4f24-a688-8889ab98952a", 251 | "metadata": { 252 | "jp-MarkdownHeadingCollapsed": true, 253 | "tags": [] 254 | }, 255 | "source": [ 256 | "## 🔸 **Combine math, comparison, and logical operators**" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 91, 262 | "id": "ab7b44a5-b6c8-4ed8-8088-37353263327a", 263 | "metadata": { 264 | "colab": { 265 | "base_uri": "https://localhost:8080/" 266 | }, 267 | "id": "JRQvZp3x_H8S", 268 | "outputId": "2e12f04a-51fc-4d67-b249-8638d9315d6f" 269 | }, 270 | "outputs": [], 271 | "source": [ 272 | "c = 6\n", 273 | "d = 2*3\n", 274 | "e = 'a'\n", 275 | "f = 'a'" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": null, 281 | "id": "86510102-ac6c-4126-86bf-993902d56422", 282 | "metadata": {}, 283 | "outputs": [], 284 | "source": [] 285 | }, 286 | { 287 | "cell_type": "markdown", 288 | "id": "babffca6-3a2f-4359-bf4d-298d55913d42", 289 | "metadata": { 290 | "jp-MarkdownHeadingCollapsed": true, 291 | "tags": [] 292 | }, 293 | "source": [ 294 | "## 🔸 **Chained comparisons**" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": null, 300 | "id": "fbfe7149-9eef-4492-a453-a54ff1eae169", 301 | "metadata": {}, 302 | "outputs": [], 303 | "source": [] 304 | }, 305 | { 306 | "cell_type": "markdown", 307 | "id": "e768ea15-f558-4bca-ae54-7ac94b2b70c7", 308 | "metadata": { 309 | "jp-MarkdownHeadingCollapsed": true, 310 | "tags": [] 311 | }, 312 | "source": [ 313 | "## 🔸 **any & all**" 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": 1, 319 | "id": "4292b0e3-b970-4853-9375-7b2c25bff02f", 320 | "metadata": { 321 | "colab": { 322 | "base_uri": "https://localhost:8080/" 323 | }, 324 | "id": "JRQvZp3x_H8S", 325 | "outputId": "2e12f04a-51fc-4d67-b249-8638d9315d6f" 326 | }, 327 | "outputs": [], 328 | "source": [ 329 | "a = [False, True, False]\n", 330 | "b = [True, True]" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": null, 336 | "id": "6e67a6b0-5167-4e42-8c9f-b7864ecfd720", 337 | "metadata": {}, 338 | "outputs": [], 339 | "source": [] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 2, 344 | "id": "594a287d-8a07-46cf-a7e7-f44040d65cba", 345 | "metadata": {}, 346 | "outputs": [], 347 | "source": [ 348 | "a = [0, -1, -2]" 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": null, 354 | "id": "0bce372f-927f-4760-a002-d2b4b9b8ce20", 355 | "metadata": {}, 356 | "outputs": [], 357 | "source": [] 358 | }, 359 | { 360 | "cell_type": "markdown", 361 | "id": "aba39402-60ad-4f92-aa11-e4d3b7eca3e9", 362 | "metadata": { 363 | "id": "kr0lLhUw072R", 364 | "jp-MarkdownHeadingCollapsed": true, 365 | "tags": [] 366 | }, 367 | "source": [ 368 | "## **✍️ Example 1: Impelement $XOR$**" 369 | ] 370 | }, 371 | { 372 | "cell_type": "markdown", 373 | "id": "d14d2fa2-beed-4f15-b2b3-149ffb935c64", 374 | "metadata": { 375 | "jp-MarkdownHeadingCollapsed": true, 376 | "tags": [] 377 | }, 378 | "source": [ 379 | "### $XOR(A,B) = (A \\land \\bar{B}) \\lor (\\bar{A} \\land B)$" 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "execution_count": 3, 385 | "id": "20e27c22-6675-4c60-97b2-b47ae0092069", 386 | "metadata": { 387 | "colab": { 388 | "base_uri": "https://localhost:8080/" 389 | }, 390 | "id": "bExle2w_4XYb", 391 | "outputId": "505cf85f-53bf-4ad5-81e9-c4b439086b9b" 392 | }, 393 | "outputs": [], 394 | "source": [ 395 | "a = True\n", 396 | "b = True" 397 | ] 398 | }, 399 | { 400 | "cell_type": "markdown", 401 | "id": "6a3fcf35-e5a5-4bd0-9674-3cb1c7144444", 402 | "metadata": { 403 | "id": "kr0lLhUw072R", 404 | "jp-MarkdownHeadingCollapsed": true, 405 | "tags": [] 406 | }, 407 | "source": [ 408 | "## **✍️ Example 2: Check the data type**" 409 | ] 410 | }, 411 | { 412 | "cell_type": "markdown", 413 | "id": "e185b235-f3e5-4920-9575-dd3396c4161e", 414 | "metadata": {}, 415 | "source": [ 416 | "\"string" 417 | ] 418 | }, 419 | { 420 | "cell_type": "code", 421 | "execution_count": null, 422 | "id": "960d62f0-8a38-4b51-9e87-2542f781e651", 423 | "metadata": {}, 424 | "outputs": [], 425 | "source": [] 426 | }, 427 | { 428 | "cell_type": "markdown", 429 | "id": "8dd4be50-af9a-403d-bdc5-2ec2b7ee8593", 430 | "metadata": { 431 | "id": "kr0lLhUw072R", 432 | "jp-MarkdownHeadingCollapsed": true, 433 | "tags": [] 434 | }, 435 | "source": [ 436 | "## **✍️ Example 3: Grade of students**" 437 | ] 438 | }, 439 | { 440 | "cell_type": "markdown", 441 | "id": "927fb514-8cc3-47a2-a2c1-5a99abc43ddf", 442 | "metadata": {}, 443 | "source": [ 444 | "\"string\n", 445 | "\"string" 446 | ] 447 | }, 448 | { 449 | "cell_type": "code", 450 | "execution_count": 123, 451 | "id": "3e042163-0541-4144-b03a-027df5d682cd", 452 | "metadata": { 453 | "colab": { 454 | "base_uri": "https://localhost:8080/" 455 | }, 456 | "id": "bExle2w_4XYb", 457 | "outputId": "505cf85f-53bf-4ad5-81e9-c4b439086b9b" 458 | }, 459 | "outputs": [], 460 | "source": [ 461 | "names = [\"Hana\", \"Karter\", \"Landon\", \"Hector\", \"Clarence\", \"Deborah\", \"Scarlett\", \"Joe\", \"Marlene\", \"Lillianna\", \"Santos\", \"Cassius\", \"Darrell\", \"Julie\", \"Kaden\", \"Allyson\", \"Anderson\", \"Sara\", \"John\", \"Brynn\"]\n", 462 | "grades = [68, 83, 61, 70, 75, 82, 57, 5, 76, 85, 62, 71, 96, 78, 76, 68, 72, 75, 83, 93]" 463 | ] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "execution_count": null, 468 | "id": "65f76be9-721f-45fc-94ac-01aac1a3c843", 469 | "metadata": {}, 470 | "outputs": [], 471 | "source": [] 472 | } 473 | ], 474 | "metadata": { 475 | "kernelspec": { 476 | "display_name": "Python 3 (ipykernel)", 477 | "language": "python", 478 | "name": "python3" 479 | }, 480 | "language_info": { 481 | "codemirror_mode": { 482 | "name": "ipython", 483 | "version": 3 484 | }, 485 | "file_extension": ".py", 486 | "mimetype": "text/x-python", 487 | "name": "python", 488 | "nbconvert_exporter": "python", 489 | "pygments_lexer": "ipython3", 490 | "version": "3.9.15" 491 | } 492 | }, 493 | "nbformat": 4, 494 | "nbformat_minor": 5 495 | } 496 | -------------------------------------------------------------------------------- /python/templates/section-2-operators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b5a35374-73fa-40c4-a707-ec33ea846df3", 6 | "metadata": { 7 | "id": "pbxR79EUAYW_", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 2: Operators 🧮**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": null, 17 | "id": "a93d4c70-96d2-4052-a2b2-091311617d27", 18 | "metadata": { 19 | "id": "gohcMHEfHNZe" 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "a = 5\n", 24 | "b = 2" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "id": "a230c9fa-0f85-439f-a296-f19e1578cfa2", 30 | "metadata": { 31 | "jp-MarkdownHeadingCollapsed": true, 32 | "tags": [] 33 | }, 34 | "source": [ 35 | "## **🔸 Mathematical Operations**" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "id": "ba43a7c7-d556-4f9b-8099-58585b922b6a", 41 | "metadata": { 42 | "jp-MarkdownHeadingCollapsed": true, 43 | "tags": [] 44 | }, 45 | "source": [ 46 | "### addition" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "id": "c41296ef-70bf-4708-ac36-84cc005270e8", 53 | "metadata": { 54 | "colab": { 55 | "base_uri": "https://localhost:8080/" 56 | }, 57 | "id": "kd3GTU8ZHUS9", 58 | "outputId": "f1465461-9e65-4d60-d788-34bf318daf8f" 59 | }, 60 | "outputs": [], 61 | "source": [] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "id": "32efb18e-2397-47fb-9c64-8165e9a057c3", 66 | "metadata": { 67 | "jp-MarkdownHeadingCollapsed": true, 68 | "tags": [] 69 | }, 70 | "source": [ 71 | "### subtraction " 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "id": "ca64bd78-06bc-4309-9811-3709d7ad5c99", 78 | "metadata": { 79 | "colab": { 80 | "base_uri": "https://localhost:8080/" 81 | }, 82 | "id": "TcNxhrC6Hbhv", 83 | "outputId": "9f3f3bad-888e-4eae-c02c-2951813c3343" 84 | }, 85 | "outputs": [], 86 | "source": [] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "id": "efce5c08-3808-48b6-9974-25594af67b7d", 91 | "metadata": { 92 | "jp-MarkdownHeadingCollapsed": true, 93 | "tags": [] 94 | }, 95 | "source": [ 96 | "### multiplication " 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "id": "8df81297-ddcb-4b44-af27-e2c16f4acc07", 103 | "metadata": { 104 | "colab": { 105 | "base_uri": "https://localhost:8080/" 106 | }, 107 | "id": "H_RzhG4NHhWb", 108 | "outputId": "16edb425-b047-4cb9-cc57-d2c471bbec41" 109 | }, 110 | "outputs": [], 111 | "source": [] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "id": "32506a29-f164-4e68-816f-66838ea25f4d", 116 | "metadata": { 117 | "jp-MarkdownHeadingCollapsed": true, 118 | "tags": [] 119 | }, 120 | "source": [ 121 | "### division" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "id": "b210a2eb-de0a-4b66-a7ac-d58c21c9e67f", 128 | "metadata": { 129 | "colab": { 130 | "base_uri": "https://localhost:8080/" 131 | }, 132 | "id": "ef_SJvdfHmsh", 133 | "outputId": "539bb96b-72eb-461a-f6a9-46f02d322b32" 134 | }, 135 | "outputs": [], 136 | "source": [] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "id": "b101ca52-250a-4006-87f8-203acbee0458", 141 | "metadata": { 142 | "jp-MarkdownHeadingCollapsed": true, 143 | "tags": [] 144 | }, 145 | "source": [ 146 | "### power" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": null, 152 | "id": "c307a80a-e6c8-4cde-8a44-98a671c6c40b", 153 | "metadata": { 154 | "colab": { 155 | "base_uri": "https://localhost:8080/" 156 | }, 157 | "id": "5p4Of7z9HsRZ", 158 | "outputId": "19856f33-6bb3-4a86-d437-53936ad6ec98" 159 | }, 160 | "outputs": [], 161 | "source": [] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "id": "78b0c451-31c7-4bdb-8fe0-df168375927f", 166 | "metadata": { 167 | "jp-MarkdownHeadingCollapsed": true, 168 | "tags": [] 169 | }, 170 | "source": [ 171 | "### remainder" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": null, 177 | "id": "7cd865f0-ef00-45b5-b695-7826c7413a37", 178 | "metadata": { 179 | "colab": { 180 | "base_uri": "https://localhost:8080/" 181 | }, 182 | "id": "ndDH0LMhH5pU", 183 | "outputId": "e09161a8-86fb-4955-d743-2bc77a234465" 184 | }, 185 | "outputs": [], 186 | "source": [] 187 | }, 188 | { 189 | "cell_type": "markdown", 190 | "id": "bb8bd663-7608-41bc-8eb0-ba79ec292c62", 191 | "metadata": { 192 | "jp-MarkdownHeadingCollapsed": true, 193 | "tags": [] 194 | }, 195 | "source": [ 196 | "### quo" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "id": "46943007-27e1-48d7-9e3c-6ad83d2c67f5", 203 | "metadata": { 204 | "colab": { 205 | "base_uri": "https://localhost:8080/" 206 | }, 207 | "id": "Gx4lscvsIA3O", 208 | "outputId": "2f4e242e-a023-4d84-da3a-f522c2efe866" 209 | }, 210 | "outputs": [], 211 | "source": [] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "id": "87dbdd5b-13a3-4118-b8d0-9882241991df", 216 | "metadata": { 217 | "jp-MarkdownHeadingCollapsed": true, 218 | "tags": [] 219 | }, 220 | "source": [ 221 | "## **🔸 Operators Precedence**" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "id": "55fddd5a-c68d-4b7d-8394-4ede83f26018", 227 | "metadata": {}, 228 | "source": [ 229 | "\"string" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": null, 235 | "id": "915dd4a4-bacc-470a-9b5e-3336da477cbd", 236 | "metadata": {}, 237 | "outputs": [], 238 | "source": [] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "id": "7d35e47c-caf0-4fa2-8ffb-2ed1495ed473", 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [] 247 | }, 248 | { 249 | "cell_type": "markdown", 250 | "id": "ad7260f2-3f99-4e30-a8c2-1f7c6d27eb43", 251 | "metadata": { 252 | "id": "w1bdIbUgIP8q", 253 | "jp-MarkdownHeadingCollapsed": true, 254 | "tags": [] 255 | }, 256 | "source": [ 257 | "## **🔸 Assignment operators**" 258 | ] 259 | }, 260 | { 261 | "cell_type": "markdown", 262 | "id": "a4245fc4-b3ca-4ac6-9bd8-ed400933fece", 263 | "metadata": { 264 | "jp-MarkdownHeadingCollapsed": true, 265 | "tags": [] 266 | }, 267 | "source": [ 268 | "### Simple assignment operator" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": null, 274 | "id": "8809c0a5-bdc8-4f44-8585-dfafb8b88d22", 275 | "metadata": { 276 | "colab": { 277 | "base_uri": "https://localhost:8080/" 278 | }, 279 | "id": "VKF7oPlaIWBt", 280 | "outputId": "7089a9e1-85a1-4b67-f3e0-c85fcd1b3be3" 281 | }, 282 | "outputs": [], 283 | "source": [] 284 | }, 285 | { 286 | "cell_type": "markdown", 287 | "id": "27c01bc3-85f0-4e23-99fb-0b89fbee600b", 288 | "metadata": { 289 | "jp-MarkdownHeadingCollapsed": true, 290 | "tags": [] 291 | }, 292 | "source": [ 293 | "### Add and equal operator" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": null, 299 | "id": "76695033-8667-4e76-b6f6-9ccfef54872e", 300 | "metadata": { 301 | "colab": { 302 | "base_uri": "https://localhost:8080/" 303 | }, 304 | "id": "qkhXfdZFIgaT", 305 | "outputId": "ac9fbbeb-b80c-465c-c93c-8fbaeecb74ba" 306 | }, 307 | "outputs": [], 308 | "source": [] 309 | }, 310 | { 311 | "cell_type": "markdown", 312 | "id": "1f07173a-aa7e-4080-9099-fe923ea8ceb9", 313 | "metadata": { 314 | "jp-MarkdownHeadingCollapsed": true, 315 | "tags": [] 316 | }, 317 | "source": [ 318 | "### Subtract and equal operator" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": null, 324 | "id": "0dde5a9b-8f4c-48ec-a3c0-13a74c113161", 325 | "metadata": { 326 | "colab": { 327 | "base_uri": "https://localhost:8080/" 328 | }, 329 | "id": "ksnetuV9IvW-", 330 | "outputId": "1435dbb2-5c6b-4a9b-ef8b-45fef2faee4b" 331 | }, 332 | "outputs": [], 333 | "source": [] 334 | }, 335 | { 336 | "cell_type": "markdown", 337 | "id": "1debcb1f-746f-4b75-b033-80d1e48f35c7", 338 | "metadata": { 339 | "jp-MarkdownHeadingCollapsed": true, 340 | "tags": [] 341 | }, 342 | "source": [ 343 | "### Multiply and equal operator" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": null, 349 | "id": "6800466a-05f7-41c3-8912-198a3a8c7de4", 350 | "metadata": { 351 | "colab": { 352 | "base_uri": "https://localhost:8080/" 353 | }, 354 | "id": "w5p1yKFJIqOu", 355 | "outputId": "7ad35685-a460-4d8b-ac48-e79de4959290" 356 | }, 357 | "outputs": [], 358 | "source": [] 359 | }, 360 | { 361 | "cell_type": "markdown", 362 | "id": "d3c3b869-9d80-4089-af0f-6bf33fc5eded", 363 | "metadata": { 364 | "jp-MarkdownHeadingCollapsed": true, 365 | "tags": [] 366 | }, 367 | "source": [ 368 | "### Divide and equal operator" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": null, 374 | "id": "17653001-b8ba-4902-a9ca-8b9efe91538c", 375 | "metadata": { 376 | "colab": { 377 | "base_uri": "https://localhost:8080/" 378 | }, 379 | "id": "TpyFapIaI06D", 380 | "outputId": "f17fef4c-013e-4cd5-fc29-8c106e5a78ff" 381 | }, 382 | "outputs": [], 383 | "source": [] 384 | }, 385 | { 386 | "cell_type": "code", 387 | "execution_count": null, 388 | "id": "9db1014e-b862-4605-a1fd-ef096385b81d", 389 | "metadata": {}, 390 | "outputs": [], 391 | "source": [] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": null, 396 | "id": "cb4a6b63-c35a-4b56-b04a-534ec8618e06", 397 | "metadata": {}, 398 | "outputs": [], 399 | "source": [] 400 | }, 401 | { 402 | "cell_type": "markdown", 403 | "id": "d7fefbbf-d800-4e40-ad45-2c0d5991298e", 404 | "metadata": { 405 | "jp-MarkdownHeadingCollapsed": true, 406 | "tags": [] 407 | }, 408 | "source": [ 409 | "## **✍️ Example 1: volume of a cylinder**" 410 | ] 411 | }, 412 | { 413 | "cell_type": "markdown", 414 | "id": "f2cf3154-3398-4ca0-97ab-13e1d3e34450", 415 | "metadata": {}, 416 | "source": [ 417 | "\"string" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "id": "64072bde-0c17-4f97-9002-640b66c86984", 424 | "metadata": { 425 | "colab": { 426 | "base_uri": "https://localhost:8080/" 427 | }, 428 | "id": "Pkqhu4FWhSW1", 429 | "outputId": "6ebd4f1e-a4f3-4c55-fb17-c10708ed43a7" 430 | }, 431 | "outputs": [], 432 | "source": [] 433 | }, 434 | { 435 | "cell_type": "markdown", 436 | "id": "f903fe39-8106-4c39-a3ea-a8d4c70796c0", 437 | "metadata": { 438 | "id": "dc4_32i9arwQ", 439 | "jp-MarkdownHeadingCollapsed": true, 440 | "tags": [] 441 | }, 442 | "source": [ 443 | "## **✍️ Example 2: BMI**" 444 | ] 445 | }, 446 | { 447 | "cell_type": "markdown", 448 | "id": "2da4e4d8-9eb5-4d61-919a-cf3eaab02283", 449 | "metadata": { 450 | "id": "2658TWO5ftjq" 451 | }, 452 | "source": [ 453 | "\"string" 454 | ] 455 | }, 456 | { 457 | "cell_type": "code", 458 | "execution_count": null, 459 | "id": "26766ef3-1e0b-40d7-b86a-152da406995e", 460 | "metadata": {}, 461 | "outputs": [], 462 | "source": [] 463 | }, 464 | { 465 | "cell_type": "markdown", 466 | "id": "65641fa2-459f-4de4-a7bb-3746663725e3", 467 | "metadata": { 468 | "id": "dc4_32i9arwQ", 469 | "jp-MarkdownHeadingCollapsed": true, 470 | "tags": [] 471 | }, 472 | "source": [ 473 | "## **✍️ Example 3: Gaussian**" 474 | ] 475 | }, 476 | { 477 | "cell_type": "markdown", 478 | "id": "af8e5884-0a00-43b3-8d5e-5d85de267b6d", 479 | "metadata": { 480 | "id": "2658TWO5ftjq" 481 | }, 482 | "source": [ 483 | "\"string" 484 | ] 485 | }, 486 | { 487 | "cell_type": "code", 488 | "execution_count": null, 489 | "id": "89b56371-787e-4713-8a67-d7001ea6c25b", 490 | "metadata": {}, 491 | "outputs": [], 492 | "source": [] 493 | } 494 | ], 495 | "metadata": { 496 | "kernelspec": { 497 | "display_name": "Python 3 (ipykernel)", 498 | "language": "python", 499 | "name": "python3" 500 | }, 501 | "language_info": { 502 | "codemirror_mode": { 503 | "name": "ipython", 504 | "version": 3 505 | }, 506 | "file_extension": ".py", 507 | "mimetype": "text/x-python", 508 | "name": "python", 509 | "nbconvert_exporter": "python", 510 | "pygments_lexer": "ipython3", 511 | "version": "3.9.15" 512 | } 513 | }, 514 | "nbformat": 4, 515 | "nbformat_minor": 5 516 | } 517 | -------------------------------------------------------------------------------- /python/templates/section-6-loops.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "352040ee-56bd-4e5d-bd9b-73e7b43a49de", 6 | "metadata": { 7 | "id": "-eY5YTudUYkh", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 6: Loops** ➰" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "ddd59530-0aba-49f3-a437-753e0d3c9e83", 17 | "metadata": {}, 18 | "source": [ 19 | "\"string" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "cb2aa1ec-d88f-4b3a-a032-8eaaed5913b0", 25 | "metadata": { 26 | "id": "y7wJBq3RUhkS", 27 | "jp-MarkdownHeadingCollapsed": true, 28 | "tags": [] 29 | }, 30 | "source": [ 31 | "## 🔸 **for loop**" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "id": "baeca37b-3901-4372-96d8-ff0c2982579e", 37 | "metadata": {}, 38 | "source": [ 39 | "\"string" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": null, 45 | "id": "a3a6a62c-5adf-4e94-8035-e3b1390fea33", 46 | "metadata": { 47 | "colab": { 48 | "base_uri": "https://localhost:8080/" 49 | }, 50 | "id": "yVKwkD77U_EQ", 51 | "outputId": "5aa247ca-c6ad-4676-c590-77285fea0b3b" 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "for x in [1, 2, 3, 4, 5]:\n", 56 | " print(x, end=' ')" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "id": "2aa0716c-32a9-4852-b460-ae35400a13c0", 62 | "metadata": { 63 | "jp-MarkdownHeadingCollapsed": true, 64 | "tags": [] 65 | }, 66 | "source": [ 67 | "### Loop in a `list` with different types" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "id": "35a3974f-7145-4de6-84cf-57ff911e4935", 74 | "metadata": { 75 | "colab": { 76 | "base_uri": "https://localhost:8080/" 77 | }, 78 | "id": "yVKwkD77U_EQ", 79 | "outputId": "5aa247ca-c6ad-4676-c590-77285fea0b3b" 80 | }, 81 | "outputs": [], 82 | "source": [ 83 | "a = ['salam', True, 3, 4, 5]\n" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "id": "80d2ac34-5a12-4bcc-af76-fcab4ee6b879", 89 | "metadata": { 90 | "jp-MarkdownHeadingCollapsed": true, 91 | "tags": [] 92 | }, 93 | "source": [ 94 | "### Loop using `range`" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": null, 100 | "id": "cf6f078e-ce10-460b-bbbf-066a5ff4bdfe", 101 | "metadata": { 102 | "id": "fxSu6iH3Vulw" 103 | }, 104 | "outputs": [], 105 | "source": [] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "id": "bdaf50ce-1ff7-48c3-b51a-430a3cd2f366", 110 | "metadata": { 111 | "jp-MarkdownHeadingCollapsed": true, 112 | "tags": [] 113 | }, 114 | "source": [ 115 | "### Loop over `str`" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "id": "8417e650-6bf9-43db-9fca-270984afaee2", 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "id": "4f3e9a53-562b-4d5e-986e-09cf3e517fa4", 129 | "metadata": { 130 | "jp-MarkdownHeadingCollapsed": true, 131 | "tags": [] 132 | }, 133 | "source": [ 134 | "### Debug" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "id": "a527ee97-4605-451c-b727-6e76cce33e30", 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [ 144 | "for y in range(12):\n", 145 | " print(y)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "id": "11b97a19-de1e-43e2-b51b-89edddec9ac5", 151 | "metadata": { 152 | "jp-MarkdownHeadingCollapsed": true, 153 | "tags": [] 154 | }, 155 | "source": [ 156 | "## 🔸 **Advanced forms of for loop**" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "id": "ec7d8f32-efd7-4499-b694-e98b7e729b72", 162 | "metadata": { 163 | "jp-MarkdownHeadingCollapsed": true, 164 | "tags": [] 165 | }, 166 | "source": [ 167 | "### Nested loops" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "id": "c0fe588b-9db3-4cf3-9531-96dcc7927648", 174 | "metadata": {}, 175 | "outputs": [], 176 | "source": [ 177 | "mat = [[1, 2, 3], \n", 178 | " [4, 5, 6], \n", 179 | " [7, 8, 9]]" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "id": "d0f2a442-1832-433b-88c1-ce36774fd799", 186 | "metadata": {}, 187 | "outputs": [], 188 | "source": [] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "id": "0e325939-59aa-4576-9a51-fc8d6c9887a3", 194 | "metadata": {}, 195 | "outputs": [], 196 | "source": [] 197 | }, 198 | { 199 | "cell_type": "markdown", 200 | "id": "91b346ed-4229-4106-bc9e-4d52352dcf10", 201 | "metadata": { 202 | "jp-MarkdownHeadingCollapsed": true, 203 | "tags": [] 204 | }, 205 | "source": [ 206 | "### for & if" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "id": "03b91ba0-0f03-4f32-bbbe-9154ced24ec7", 212 | "metadata": { 213 | "jp-MarkdownHeadingCollapsed": true, 214 | "tags": [] 215 | }, 216 | "source": [ 217 | "Print even numbers less than $30$" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": null, 223 | "id": "443e6f46-8846-4f81-a3c3-2fd2196592b7", 224 | "metadata": { 225 | "colab": { 226 | "base_uri": "https://localhost:8080/" 227 | }, 228 | "id": "EzVoLSWaW-F9", 229 | "outputId": "f778016f-3172-4905-aaf3-a79efbaded19" 230 | }, 231 | "outputs": [], 232 | "source": [] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "id": "b6ebff3a-84bb-485d-8212-cacc690a2f97", 237 | "metadata": { 238 | "jp-MarkdownHeadingCollapsed": true, 239 | "tags": [] 240 | }, 241 | "source": [ 242 | "### for loop in complex lists" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": null, 248 | "id": "c7673b53-7292-4796-a7cc-914785e15927", 249 | "metadata": {}, 250 | "outputs": [], 251 | "source": [ 252 | "mat = [['Ali', 20, 0], ['Hanieh', 19], ['Mahsa', 20, 0], ['Shahin', 18, 1]]\n", 253 | "\n" 254 | ] 255 | }, 256 | { 257 | "cell_type": "markdown", 258 | "id": "4f32db3c-5f08-496a-8cb0-42d53a545d5b", 259 | "metadata": { 260 | "jp-MarkdownHeadingCollapsed": true, 261 | "tags": [] 262 | }, 263 | "source": [ 264 | "## 🔸 **for loop in one line**" 265 | ] 266 | }, 267 | { 268 | "cell_type": "markdown", 269 | "id": "bcfbfdd2-0f40-4125-b169-0f5fe219ba86", 270 | "metadata": {}, 271 | "source": [ 272 | "\"string" 273 | ] 274 | }, 275 | { 276 | "cell_type": "markdown", 277 | "id": "3c84a369-17a5-4822-a53a-95573e6b5519", 278 | "metadata": {}, 279 | "source": [ 280 | "\"string" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": null, 286 | "id": "198a2cd7-dd22-4c84-9cd3-cb654f555970", 287 | "metadata": {}, 288 | "outputs": [], 289 | "source": [] 290 | }, 291 | { 292 | "cell_type": "markdown", 293 | "id": "7dd25c66-7fb6-4c90-9480-e6bd649abf62", 294 | "metadata": { 295 | "jp-MarkdownHeadingCollapsed": true, 296 | "tags": [] 297 | }, 298 | "source": [ 299 | "### Add $1$ to each item in `list`" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": null, 305 | "id": "1cecb643-6b69-423a-b862-98a1f2657bdd", 306 | "metadata": {}, 307 | "outputs": [], 308 | "source": [ 309 | "numbers = [5, 2, 4, 6, 7, 2, 3]\n" 310 | ] 311 | }, 312 | { 313 | "cell_type": "markdown", 314 | "id": "af53becf-5344-400d-bbc8-c6fd882ca6b7", 315 | "metadata": { 316 | "jp-MarkdownHeadingCollapsed": true, 317 | "tags": [] 318 | }, 319 | "source": [ 320 | "### Create a list with even numbers" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": null, 326 | "id": "55c9b154-a539-4b80-b83e-f13eac54f47d", 327 | "metadata": {}, 328 | "outputs": [], 329 | "source": [] 330 | }, 331 | { 332 | "cell_type": "markdown", 333 | "id": "5228609d-65e8-4008-b2e5-67626885b0ac", 334 | "metadata": { 335 | "id": "zwc-EbQqagVr", 336 | "jp-MarkdownHeadingCollapsed": true, 337 | "tags": [] 338 | }, 339 | "source": [ 340 | "## 🔸 **while loop**" 341 | ] 342 | }, 343 | { 344 | "cell_type": "markdown", 345 | "id": "d0cf7aa7-e105-4bc6-a731-e0474172fa16", 346 | "metadata": {}, 347 | "source": [ 348 | "\"string" 349 | ] 350 | }, 351 | { 352 | "cell_type": "markdown", 353 | "id": "9f76f3cb-8cb4-4475-9370-d307cda3f33e", 354 | "metadata": { 355 | "jp-MarkdownHeadingCollapsed": true, 356 | "tags": [] 357 | }, 358 | "source": [ 359 | "### print numbers less than $10$" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": null, 365 | "id": "d80cac10-7e0f-4b70-bba8-f0d01d34fb8c", 366 | "metadata": { 367 | "colab": { 368 | "base_uri": "https://localhost:8080/" 369 | }, 370 | "id": "tSygM0qWaiJ-", 371 | "outputId": "bee0b72a-1b41-463d-c121-d15f40bb3a96" 372 | }, 373 | "outputs": [], 374 | "source": [ 375 | "num = 0\n", 376 | "while num <= 10:\n", 377 | " print(num, end=' ')\n", 378 | " num += 0.5" 379 | ] 380 | }, 381 | { 382 | "cell_type": "markdown", 383 | "id": "37a54af2-6e7a-45c4-846c-451ea678a150", 384 | "metadata": { 385 | "jp-MarkdownHeadingCollapsed": true, 386 | "tags": [] 387 | }, 388 | "source": [ 389 | "### factorial" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "execution_count": null, 395 | "id": "fbefe026-e0d7-4ca7-8cd2-bb949d195866", 396 | "metadata": { 397 | "colab": { 398 | "base_uri": "https://localhost:8080/" 399 | }, 400 | "id": "aHpJJWPybiCj", 401 | "outputId": "4fdb0c56-5401-4b3e-9bdd-2646530ca9a7" 402 | }, 403 | "outputs": [], 404 | "source": [] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": null, 409 | "id": "8eed97e4-ff6e-4b23-a1b8-31d371a9bcab", 410 | "metadata": {}, 411 | "outputs": [], 412 | "source": [] 413 | }, 414 | { 415 | "cell_type": "markdown", 416 | "id": "7fcc923c-4581-488b-af3c-748704e7fad3", 417 | "metadata": { 418 | "jp-MarkdownHeadingCollapsed": true, 419 | "tags": [] 420 | }, 421 | "source": [ 422 | "## 🔸 **break**" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "id": "dbe27a53-646c-41bd-819e-ebb87a5bd95a", 429 | "metadata": {}, 430 | "outputs": [], 431 | "source": [] 432 | }, 433 | { 434 | "cell_type": "markdown", 435 | "id": "a40e11b7-beb5-43dc-a92a-8e803afe38ca", 436 | "metadata": { 437 | "jp-MarkdownHeadingCollapsed": true, 438 | "tags": [] 439 | }, 440 | "source": [ 441 | "### check if $-1$ exists in `list`" 442 | ] 443 | }, 444 | { 445 | "cell_type": "code", 446 | "execution_count": null, 447 | "id": "b5ac5f99-9d87-4eb3-8653-8bbbaa2aa803", 448 | "metadata": {}, 449 | "outputs": [], 450 | "source": [ 451 | "a = [10, 4, 9, 1, 2, -1, 7, 5, 16, 14]\n" 452 | ] 453 | }, 454 | { 455 | "cell_type": "markdown", 456 | "id": "5a4f695a-0509-4bca-a0a8-93c821df599e", 457 | "metadata": { 458 | "jp-MarkdownHeadingCollapsed": true, 459 | "tags": [] 460 | }, 461 | "source": [ 462 | "## 🔸 **continue**" 463 | ] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "execution_count": null, 468 | "id": "157a4956", 469 | "metadata": {}, 470 | "outputs": [], 471 | "source": [] 472 | }, 473 | { 474 | "cell_type": "markdown", 475 | "id": "b3b436af-457d-465a-8b08-7d7712b0dcc3", 476 | "metadata": { 477 | "tags": [] 478 | }, 479 | "source": [ 480 | "### Print items of `list10` except $12$" 481 | ] 482 | }, 483 | { 484 | "cell_type": "code", 485 | "execution_count": null, 486 | "id": "c758cc75-e002-48bf-a097-4cebc2815bf5", 487 | "metadata": {}, 488 | "outputs": [], 489 | "source": [ 490 | "a = [10, 4, 9, 1, 2, 12, 7, 5, 16, 14]\n" 491 | ] 492 | }, 493 | { 494 | "cell_type": "markdown", 495 | "id": "8fab1681-03da-46ea-9247-9b15deae4017", 496 | "metadata": { 497 | "id": "rb1dy-lucz58", 498 | "jp-MarkdownHeadingCollapsed": true, 499 | "tags": [] 500 | }, 501 | "source": [ 502 | "## **✍️ Example 1: Hop game**" 503 | ] 504 | }, 505 | { 506 | "cell_type": "markdown", 507 | "id": "f7a69cc6-b4a4-44fe-bb58-cf7e8bb91fba", 508 | "metadata": {}, 509 | "source": [ 510 | "\"string" 511 | ] 512 | }, 513 | { 514 | "cell_type": "code", 515 | "execution_count": null, 516 | "id": "f26aa7c3-6e68-4002-8699-63e56b72f88b", 517 | "metadata": { 518 | "id": "yTB3RLzqc3yE" 519 | }, 520 | "outputs": [], 521 | "source": [] 522 | }, 523 | { 524 | "cell_type": "markdown", 525 | "id": "df1df14d-dccc-4ba4-a5c4-e89a719a04a7", 526 | "metadata": { 527 | "id": "rb1dy-lucz58", 528 | "jp-MarkdownHeadingCollapsed": true, 529 | "tags": [] 530 | }, 531 | "source": [ 532 | "## **✍️ Example 2: Fibonacci series**" 533 | ] 534 | }, 535 | { 536 | "cell_type": "markdown", 537 | "id": "0f44c315-e4f9-4a91-828e-dced20bac57f", 538 | "metadata": {}, 539 | "source": [ 540 | "\"string" 541 | ] 542 | }, 543 | { 544 | "cell_type": "code", 545 | "execution_count": null, 546 | "id": "f23d8139-634b-4cf5-88cb-8e4b3f930898", 547 | "metadata": { 548 | "colab": { 549 | "base_uri": "https://localhost:8080/" 550 | }, 551 | "id": "3mgUYl94dvNE", 552 | "outputId": "360230f2-1e21-4cd5-cdae-2147b06e68a0" 553 | }, 554 | "outputs": [], 555 | "source": [] 556 | }, 557 | { 558 | "cell_type": "code", 559 | "execution_count": null, 560 | "id": "914db637-1085-43b1-8502-53c3e415ad4f", 561 | "metadata": {}, 562 | "outputs": [], 563 | "source": [] 564 | }, 565 | { 566 | "cell_type": "markdown", 567 | "id": "797bbdf8-59f2-4194-87ef-e2f69b9dbe3b", 568 | "metadata": { 569 | "id": "rb1dy-lucz58", 570 | "jp-MarkdownHeadingCollapsed": true, 571 | "tags": [] 572 | }, 573 | "source": [ 574 | "## **✍️ Example 3: Count without `count`!**" 575 | ] 576 | }, 577 | { 578 | "cell_type": "markdown", 579 | "id": "4007b2dc-8d67-4773-bacd-44f255faba44", 580 | "metadata": {}, 581 | "source": [ 582 | "\"string" 583 | ] 584 | }, 585 | { 586 | "cell_type": "code", 587 | "execution_count": null, 588 | "id": "c62103cd-598d-4e32-80fa-91bc75a1d3ef", 589 | "metadata": { 590 | "tags": [] 591 | }, 592 | "outputs": [], 593 | "source": [] 594 | } 595 | ], 596 | "metadata": { 597 | "kernelspec": { 598 | "display_name": "Python 3 (ipykernel)", 599 | "language": "python", 600 | "name": "python3" 601 | }, 602 | "language_info": { 603 | "codemirror_mode": { 604 | "name": "ipython", 605 | "version": 3 606 | }, 607 | "file_extension": ".py", 608 | "mimetype": "text/x-python", 609 | "name": "python", 610 | "nbconvert_exporter": "python", 611 | "pygments_lexer": "ipython3", 612 | "version": "3.9.15" 613 | } 614 | }, 615 | "nbformat": 4, 616 | "nbformat_minor": 5 617 | } 618 | -------------------------------------------------------------------------------- /python/templates/section-5-conditional-statements.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f18ece75-eec3-40b1-9af8-355087006bb4", 6 | "metadata": { 7 | "id": "PB9MOYPq50Wx", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 5: Conditional Statement 🕹️**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "1bbcdf12-354f-4554-a329-486f4ed4bc68", 17 | "metadata": {}, 18 | "source": [ 19 | "\"string" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "70bb3145-2a25-4fac-8f5b-1141119323a8", 25 | "metadata": { 26 | "id": "A9c3D-3n61Du", 27 | "jp-MarkdownHeadingCollapsed": true, 28 | "tags": [] 29 | }, 30 | "source": [ 31 | "## 🔸 **if**" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "id": "ab68c888-a639-4ae5-aeea-d89f8f1e613e", 37 | "metadata": {}, 38 | "source": [ 39 | "\"string" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": null, 45 | "id": "0206a39b-3ac0-4894-9a89-ab52a4f97bb4", 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "val = False\n", 50 | "\n", 51 | "if val:\n", 52 | " print('salam')\n", 53 | " print('howsam')\n", 54 | "print('!')" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "id": "4a2c9391-f0f8-4f71-9d2f-6d89fd9a03ca", 60 | "metadata": { 61 | "jp-MarkdownHeadingCollapsed": true, 62 | "tags": [] 63 | }, 64 | "source": [ 65 | "### Is $x$ positive?" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "id": "f76d615e-5f24-4c40-adb3-3b7a23c536ec", 72 | "metadata": { 73 | "colab": { 74 | "base_uri": "https://localhost:8080/" 75 | }, 76 | "id": "1NZQwcpJ-ffr", 77 | "outputId": "6a4ac375-079e-4afe-f871-b87906c30913" 78 | }, 79 | "outputs": [], 80 | "source": [ 81 | "x = 2" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "id": "2456d509-4ad3-41e1-8e5b-a2c4b95616f3", 87 | "metadata": { 88 | "jp-MarkdownHeadingCollapsed": true, 89 | "tags": [] 90 | }, 91 | "source": [ 92 | "### Warn if number of characters are more than 50" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "id": "288a5bea-90c3-424d-8aa0-5b9bbf41f733", 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [ 102 | "sent = 'hello world! hello world! hello world! hello world! hello world!'" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "id": "7921b3b4-1d7a-4a0b-bc42-cf7f14e07a58", 108 | "metadata": { 109 | "jp-MarkdownHeadingCollapsed": true, 110 | "tags": [] 111 | }, 112 | "source": [ 113 | "### If grade is greater than or equal to 50 then display \"*passed*\" and if it's less than 50 then display \"*failed*\"" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "id": "9459903c-5ce3-4b62-a62c-ff022bca0eb6", 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "grade = 30" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "id": "344d32e1-af11-479b-8316-5a174f308763", 129 | "metadata": { 130 | "jp-MarkdownHeadingCollapsed": true, 131 | "tags": [] 132 | }, 133 | "source": [ 134 | "## 🔸 **if else**" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "id": "75a57075-b42c-4d04-8af3-704c8049606e", 140 | "metadata": {}, 141 | "source": [ 142 | "\"string" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "id": "0cd1eb00-8a06-407c-85f0-f4842f58627f", 148 | "metadata": { 149 | "jp-MarkdownHeadingCollapsed": true, 150 | "tags": [] 151 | }, 152 | "source": [ 153 | "### Is $x$ positive or negative?" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "id": "aa688056-d186-4ed2-ae39-f3f9ac6489a8", 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "x = -5" 164 | ] 165 | }, 166 | { 167 | "cell_type": "markdown", 168 | "id": "3dd2b4ea-22d0-406a-8aa1-fe9093378fc6", 169 | "metadata": { 170 | "jp-MarkdownHeadingCollapsed": true, 171 | "tags": [] 172 | }, 173 | "source": [ 174 | "### If grade is greater than or equal to 50 then display \"*passed*\" and if it's less than 50 then display \"*failed*\"" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "id": "17c61bbf-df8a-40ab-a301-9c4063c43eec", 181 | "metadata": {}, 182 | "outputs": [], 183 | "source": [ 184 | "grade = 30" 185 | ] 186 | }, 187 | { 188 | "cell_type": "markdown", 189 | "id": "7b621b52-7a50-4dbb-9099-bf1ebf777bd9", 190 | "metadata": { 191 | "jp-MarkdownHeadingCollapsed": true, 192 | "tags": [] 193 | }, 194 | "source": [ 195 | "### Implement ReLU!" 196 | ] 197 | }, 198 | { 199 | "cell_type": "markdown", 200 | "id": "50843b31-c66d-49b9-99cc-d009a116da9f", 201 | "metadata": {}, 202 | "source": [ 203 | "\"string" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "id": "6e6881f7-d998-4480-83d2-c3405f1d1db3", 210 | "metadata": { 211 | "colab": { 212 | "base_uri": "https://localhost:8080/" 213 | }, 214 | "id": "p2kobWHG6-rP", 215 | "outputId": "5745ff26-0cac-490d-d319-695cad2ba12e" 216 | }, 217 | "outputs": [], 218 | "source": [ 219 | "x = 3\n", 220 | "t = 2" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "id": "fbc88b9d-e47b-4f24-a688-8889ab98952a", 226 | "metadata": { 227 | "jp-MarkdownHeadingCollapsed": true, 228 | "tags": [] 229 | }, 230 | "source": [ 231 | "## 🔸 **if elif else**" 232 | ] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "id": "8058d476-49fd-4b21-88b3-6f706347f64d", 237 | "metadata": {}, 238 | "source": [ 239 | "\"string" 240 | ] 241 | }, 242 | { 243 | "cell_type": "markdown", 244 | "id": "e8431806-2207-4948-b3b2-10c4aebf08a0", 245 | "metadata": { 246 | "jp-MarkdownHeadingCollapsed": true, 247 | "tags": [] 248 | }, 249 | "source": [ 250 | "### Is $x$ positive, negative or zero?" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": null, 256 | "id": "863829ce-8aea-4749-8bfe-cb2537462f99", 257 | "metadata": {}, 258 | "outputs": [], 259 | "source": [ 260 | "x = 0" 261 | ] 262 | }, 263 | { 264 | "cell_type": "markdown", 265 | "id": "249a2f1a-25ca-4b7c-a4a3-446f1b0db33c", 266 | "metadata": { 267 | "tags": [] 268 | }, 269 | "source": [ 270 | "### Write code for below function" 271 | ] 272 | }, 273 | { 274 | "cell_type": "markdown", 275 | "id": "458ea71e-586c-4019-9110-9d20d94cf89d", 276 | "metadata": {}, 277 | "source": [ 278 | "\"string" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": null, 284 | "id": "cb53e335-d68c-414e-ad9c-7010e5e7f235", 285 | "metadata": { 286 | "colab": { 287 | "base_uri": "https://localhost:8080/" 288 | }, 289 | "id": "p2kobWHG6-rP", 290 | "outputId": "5745ff26-0cac-490d-d319-695cad2ba12e" 291 | }, 292 | "outputs": [], 293 | "source": [ 294 | "x = 2\n", 295 | "t1, t2 = -4, 10" 296 | ] 297 | }, 298 | { 299 | "cell_type": "markdown", 300 | "id": "babffca6-3a2f-4359-bf4d-298d55913d42", 301 | "metadata": { 302 | "jp-MarkdownHeadingCollapsed": true, 303 | "tags": [] 304 | }, 305 | "source": [ 306 | "## 🔸 **Combine math, comparison, and logical operators**" 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "id": "41995ebf-0147-4d07-ba7a-a83bdddd0654", 312 | "metadata": { 313 | "jp-MarkdownHeadingCollapsed": true, 314 | "tags": [] 315 | }, 316 | "source": [ 317 | "### Is $x$ positive and even?" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": null, 323 | "id": "fbfe7149-9eef-4492-a453-a54ff1eae169", 324 | "metadata": {}, 325 | "outputs": [], 326 | "source": [ 327 | "x = 6" 328 | ] 329 | }, 330 | { 331 | "cell_type": "markdown", 332 | "id": "e768ea15-f558-4bca-ae54-7ac94b2b70c7", 333 | "metadata": { 334 | "jp-MarkdownHeadingCollapsed": true, 335 | "tags": [] 336 | }, 337 | "source": [ 338 | "## 🔸 **Nested if**" 339 | ] 340 | }, 341 | { 342 | "cell_type": "markdown", 343 | "id": "d46f82d0-e36b-425a-baa2-daee78a49d59", 344 | "metadata": { 345 | "jp-MarkdownHeadingCollapsed": true, 346 | "tags": [] 347 | }, 348 | "source": [ 349 | "### Is $x$ positive and even or positive and odd?" 350 | ] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "execution_count": null, 355 | "id": "4292b0e3-b970-4853-9375-7b2c25bff02f", 356 | "metadata": { 357 | "colab": { 358 | "base_uri": "https://localhost:8080/" 359 | }, 360 | "id": "JRQvZp3x_H8S", 361 | "outputId": "2e12f04a-51fc-4d67-b249-8638d9315d6f" 362 | }, 363 | "outputs": [], 364 | "source": [ 365 | "x = -3" 366 | ] 367 | }, 368 | { 369 | "cell_type": "markdown", 370 | "id": "8c0fc662-83c2-4bae-a1cc-2f7c5614fba5", 371 | "metadata": { 372 | "jp-MarkdownHeadingCollapsed": true, 373 | "tags": [] 374 | }, 375 | "source": [ 376 | "## 🔸 **Conditional statements in one line**" 377 | ] 378 | }, 379 | { 380 | "cell_type": "markdown", 381 | "id": "7270a91a-e6b0-49c2-94fd-240ffbc442b1", 382 | "metadata": {}, 383 | "source": [ 384 | "\"string\n", 385 | "\"string" 386 | ] 387 | }, 388 | { 389 | "cell_type": "markdown", 390 | "id": "b1b3bd61-f0ce-44aa-853d-47bf7150bbae", 391 | "metadata": { 392 | "jp-MarkdownHeadingCollapsed": true, 393 | "tags": [] 394 | }, 395 | "source": [ 396 | "### Implement ReLU!" 397 | ] 398 | }, 399 | { 400 | "cell_type": "markdown", 401 | "id": "f26ca858-c47f-4b3e-ae51-b134bdb79ea7", 402 | "metadata": {}, 403 | "source": [ 404 | "\"string" 405 | ] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "execution_count": null, 410 | "id": "7f793e91-dec4-446b-a040-18b58164b3b7", 411 | "metadata": { 412 | "colab": { 413 | "base_uri": "https://localhost:8080/" 414 | }, 415 | "id": "p2kobWHG6-rP", 416 | "outputId": "5745ff26-0cac-490d-d319-695cad2ba12e" 417 | }, 418 | "outputs": [], 419 | "source": [ 420 | "x = 5\n", 421 | "t = 0\n", 422 | "\n", 423 | "if x <= t:\n", 424 | " y = 0\n", 425 | "else:\n", 426 | " y = x - t\n", 427 | "print('x:', x, '-->', 'y', y)" 428 | ] 429 | }, 430 | { 431 | "cell_type": "code", 432 | "execution_count": null, 433 | "id": "ca4ca30e-3f26-466f-a264-ff3e6e61033a", 434 | "metadata": {}, 435 | "outputs": [], 436 | "source": [] 437 | }, 438 | { 439 | "cell_type": "markdown", 440 | "id": "48858d07-4142-467e-85cb-d3789f6e3700", 441 | "metadata": { 442 | "jp-MarkdownHeadingCollapsed": true, 443 | "tags": [] 444 | }, 445 | "source": [ 446 | "## 🔸 **Debug & Trace**" 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": null, 452 | "id": "2623d689-223f-4e42-8b5c-791a184bb2d2", 453 | "metadata": { 454 | "colab": { 455 | "base_uri": "https://localhost:8080/" 456 | }, 457 | "id": "JRQvZp3x_H8S", 458 | "outputId": "2e12f04a-51fc-4d67-b249-8638d9315d6f" 459 | }, 460 | "outputs": [], 461 | "source": [ 462 | "x = 0\n", 463 | "\n", 464 | "if x > 0 :\n", 465 | " if x % 2 == 0:\n", 466 | " print('x is positive and even')\n", 467 | " else:\n", 468 | " print('x is positive and odd')\n", 469 | "elif x <= 0:\n", 470 | " if x % 2 == 0:\n", 471 | " print('x is negative and even')\n", 472 | " else:\n", 473 | " print('x is negative and odd')\n", 474 | "else:\n", 475 | " print('x is zero')" 476 | ] 477 | }, 478 | { 479 | "cell_type": "markdown", 480 | "id": "af524768-102c-4288-a71b-e97cd09bb8ab", 481 | "metadata": { 482 | "jp-MarkdownHeadingCollapsed": true, 483 | "tags": [] 484 | }, 485 | "source": [ 486 | "### How to trace?!" 487 | ] 488 | }, 489 | { 490 | "cell_type": "code", 491 | "execution_count": null, 492 | "id": "293016b6-a53a-4980-95cb-cb375b1d02a0", 493 | "metadata": {}, 494 | "outputs": [], 495 | "source": [ 496 | "'x is positive' if x > 0 else 'x is negative'" 497 | ] 498 | }, 499 | { 500 | "cell_type": "markdown", 501 | "id": "aba39402-60ad-4f92-aa11-e4d3b7eca3e9", 502 | "metadata": { 503 | "id": "kr0lLhUw072R", 504 | "jp-MarkdownHeadingCollapsed": true, 505 | "tags": [] 506 | }, 507 | "source": [ 508 | "## **✍️ Example 1: Beaufort scale**" 509 | ] 510 | }, 511 | { 512 | "cell_type": "markdown", 513 | "id": "d14d2fa2-beed-4f15-b2b3-149ffb935c64", 514 | "metadata": { 515 | "tags": [] 516 | }, 517 | "source": [ 518 | "\"string\n" 519 | ] 520 | }, 521 | { 522 | "cell_type": "code", 523 | "execution_count": null, 524 | "id": "20e27c22-6675-4c60-97b2-b47ae0092069", 525 | "metadata": { 526 | "colab": { 527 | "base_uri": "https://localhost:8080/" 528 | }, 529 | "id": "bExle2w_4XYb", 530 | "outputId": "505cf85f-53bf-4ad5-81e9-c4b439086b9b" 531 | }, 532 | "outputs": [], 533 | "source": [ 534 | "beaufort = 13" 535 | ] 536 | }, 537 | { 538 | "cell_type": "markdown", 539 | "id": "6a3fcf35-e5a5-4bd0-9674-3cb1c7144444", 540 | "metadata": { 541 | "id": "kr0lLhUw072R", 542 | "jp-MarkdownHeadingCollapsed": true, 543 | "tags": [] 544 | }, 545 | "source": [ 546 | "## **✍️ Example 2: Roots of quadratic equation**" 547 | ] 548 | }, 549 | { 550 | "cell_type": "markdown", 551 | "id": "e185b235-f3e5-4920-9575-dd3396c4161e", 552 | "metadata": {}, 553 | "source": [ 554 | "\"string" 555 | ] 556 | }, 557 | { 558 | "cell_type": "code", 559 | "execution_count": null, 560 | "id": "960d62f0-8a38-4b51-9e87-2542f781e651", 561 | "metadata": {}, 562 | "outputs": [], 563 | "source": [ 564 | "a, b, c = 1, 4, 2" 565 | ] 566 | }, 567 | { 568 | "cell_type": "markdown", 569 | "id": "8dd4be50-af9a-403d-bdc5-2ec2b7ee8593", 570 | "metadata": { 571 | "id": "kr0lLhUw072R", 572 | "jp-MarkdownHeadingCollapsed": true, 573 | "tags": [] 574 | }, 575 | "source": [ 576 | "## **✍️ Example 3: Sort**" 577 | ] 578 | }, 579 | { 580 | "cell_type": "markdown", 581 | "id": "927fb514-8cc3-47a2-a2c1-5a99abc43ddf", 582 | "metadata": {}, 583 | "source": [ 584 | "\"string" 585 | ] 586 | }, 587 | { 588 | "cell_type": "code", 589 | "execution_count": null, 590 | "id": "3e042163-0541-4144-b03a-027df5d682cd", 591 | "metadata": { 592 | "colab": { 593 | "base_uri": "https://localhost:8080/" 594 | }, 595 | "id": "bExle2w_4XYb", 596 | "outputId": "505cf85f-53bf-4ad5-81e9-c4b439086b9b" 597 | }, 598 | "outputs": [], 599 | "source": [ 600 | "a, b, c = 2, 5, 15" 601 | ] 602 | } 603 | ], 604 | "metadata": { 605 | "kernelspec": { 606 | "display_name": "Python 3 (ipykernel)", 607 | "language": "python", 608 | "name": "python3" 609 | }, 610 | "language_info": { 611 | "codemirror_mode": { 612 | "name": "ipython", 613 | "version": 3 614 | }, 615 | "file_extension": ".py", 616 | "mimetype": "text/x-python", 617 | "name": "python", 618 | "nbconvert_exporter": "python", 619 | "pygments_lexer": "ipython3", 620 | "version": "3.9.15" 621 | } 622 | }, 623 | "nbformat": 4, 624 | "nbformat_minor": 5 625 | } 626 | -------------------------------------------------------------------------------- /python/lectures/.ipynb_checkpoints/section-12-function-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1df7bd5d-6bcf-4cdb-b25c-4678c06593cf", 6 | "metadata": { 7 | "id": "ltDaErzDg3Hp", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 11: Function** 🧷" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "ffa8bd2f-1c7c-46b4-b30e-528597c780f6", 17 | "metadata": { 18 | "id": "duFit9Ksg7VN" 19 | }, 20 | "source": [ 21 | "\"string" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "id": "82a65f3f-2001-41d7-840d-1b38ae6017f6", 27 | "metadata": { 28 | "jp-MarkdownHeadingCollapsed": true, 29 | "tags": [] 30 | }, 31 | "source": [ 32 | "## 🔸 **How to define a function**" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "id": "68ff4894-902f-458d-b491-8bc1371ec632", 38 | "metadata": { 39 | "id": "duFit9Ksg7VN" 40 | }, 41 | "source": [ 42 | "\"string" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "id": "2ffa58ec-1275-4967-8663-336be32af35b", 48 | "metadata": { 49 | "jp-MarkdownHeadingCollapsed": true, 50 | "tags": [] 51 | }, 52 | "source": [ 53 | "### Define & Call" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 39, 59 | "id": "5d5ff606-08ce-4808-82ef-9307ae032801", 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "def avg1(a, b):\n", 64 | " return (a + b)/2" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 4, 70 | "id": "356f246e-7e0e-4689-9b65-7465b771ce12", 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "avg1(10, 20)\n", 75 | "\n", 76 | "x = avg1(10, 20)\n", 77 | "x" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "3d135f4f-bc8c-4c3f-bee8-8e8a94078fe9", 83 | "metadata": { 84 | "jp-MarkdownHeadingCollapsed": true, 85 | "tags": [] 86 | }, 87 | "source": [ 88 | "### Function without `return`" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 2, 94 | "id": "2cc901e8-5bab-4d83-a929-0d27c9e59f70", 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "def avg2(a, b):\n", 99 | " print((a + b)/2)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 9, 105 | "id": "1509dd87-c2dd-4cf4-9f05-697a9b7839fd", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "avg2(10, 20)\n", 110 | "\n", 111 | "y = avg2(10, 20)\n", 112 | "print(y)" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "id": "47faedd2-3175-4302-80b1-a2143d5c8166", 118 | "metadata": { 119 | "tags": [] 120 | }, 121 | "source": [ 122 | "### Many outputs" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 2, 128 | "id": "39b40b44-b70d-4648-b7c6-2a4c8ee1d1ae", 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "def avg2(a):\n", 133 | " return sum(a), len(a)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 9, 139 | "id": "a4f6a854-ab93-4193-91be-18c7fa9fd362", 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "avg2(10, 20)\n", 144 | "\n", 145 | "y = avg2(10, 20)\n", 146 | "print(y)" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "id": "6b13f8b6-b663-46c6-98df-ea5896b5c055", 152 | "metadata": { 153 | "jp-MarkdownHeadingCollapsed": true, 154 | "tags": [] 155 | }, 156 | "source": [ 157 | "## 🔸 **Default parameter value**" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "id": "3a5949ff-b15a-4815-81f9-098f87048985", 163 | "metadata": { 164 | "jp-MarkdownHeadingCollapsed": true, 165 | "tags": [] 166 | }, 167 | "source": [ 168 | "### Arithmetic mean or geometric mean?" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": null, 174 | "id": "bcb6415e-2cf5-47ab-b3c1-4ab48e34da69", 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "def avg(a, b, geometric):\n", 179 | " if geometric:\n", 180 | " result = (a*b)**(1/2)\n", 181 | " else:\n", 182 | " result = (a + b)/2\n", 183 | " print(result)" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "id": "5811064c-fd5e-4be5-890c-393dc9f518aa", 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "15.0\n" 197 | ] 198 | } 199 | ], 200 | "source": [ 201 | "avg(10, 20, False)" 202 | ] 203 | }, 204 | { 205 | "cell_type": "markdown", 206 | "id": "b4a65616-55e7-4f29-a46d-e3e23f320044", 207 | "metadata": { 208 | "jp-MarkdownHeadingCollapsed": true, 209 | "tags": [] 210 | }, 211 | "source": [ 212 | "### `geometric` argument with default value" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "id": "81c3cdd6-9af7-44f2-9650-01cdecfe901c", 219 | "metadata": {}, 220 | "outputs": [], 221 | "source": [ 222 | "def avg(a, b, geometric=False):\n", 223 | " if geometric:\n", 224 | " result = (a*b)**(1/2)\n", 225 | " else:\n", 226 | " result = (a + b)/2\n", 227 | " print(result)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": null, 233 | "id": "345d3318-1005-4c78-8dbf-8ac04b5eb5ac", 234 | "metadata": {}, 235 | "outputs": [], 236 | "source": [ 237 | "avg(10, 20)" 238 | ] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "id": "6563b8e3-b2aa-4f50-a5e6-7ebb9d957b2d", 243 | "metadata": { 244 | "jp-MarkdownHeadingCollapsed": true, 245 | "tags": [] 246 | }, 247 | "source": [ 248 | "## 🔸 **Unknown number of inputs**" 249 | ] 250 | }, 251 | { 252 | "cell_type": "markdown", 253 | "id": "2c79d22b-8dd7-4654-806d-37c5566f2b1c", 254 | "metadata": { 255 | "jp-MarkdownHeadingCollapsed": true, 256 | "tags": [] 257 | }, 258 | "source": [ 259 | "### *args" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 1, 265 | "id": "894bc925-1771-487d-817a-bd9d6fe17bd9", 266 | "metadata": {}, 267 | "outputs": [], 268 | "source": [ 269 | "def avg(*inputs):\n", 270 | " summ = 0\n", 271 | " for num in inputs:\n", 272 | " summ += num\n", 273 | " result = summ/len(inputs)\n", 274 | " return result" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 2, 280 | "id": "2a3080a1-6506-4c68-9075-ecb37cf5981e", 281 | "metadata": {}, 282 | "outputs": [ 283 | { 284 | "name": "stdout", 285 | "output_type": "stream", 286 | "text": [ 287 | "(10, 20, 30, 40)\n" 288 | ] 289 | }, 290 | { 291 | "data": { 292 | "text/plain": [ 293 | "25.0" 294 | ] 295 | }, 296 | "execution_count": 2, 297 | "metadata": {}, 298 | "output_type": "execute_result" 299 | } 300 | ], 301 | "source": [ 302 | "avg(10, 20, 30, 40)" 303 | ] 304 | }, 305 | { 306 | "cell_type": "markdown", 307 | "id": "95362799-f325-4786-988d-30613f1c2d0a", 308 | "metadata": { 309 | "jp-MarkdownHeadingCollapsed": true, 310 | "tags": [] 311 | }, 312 | "source": [ 313 | "### **kwargs" 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": 21, 319 | "id": "71418ff3-d690-49b7-80a5-09230851c86b", 320 | "metadata": {}, 321 | "outputs": [], 322 | "source": [ 323 | "def avg_score(**inputs):\n", 324 | " averages = {}\n", 325 | " for key in inputs:\n", 326 | " averages[key] = sum(inputs[key])/len(inputs[key])\n", 327 | " return averages" 328 | ] 329 | }, 330 | { 331 | "cell_type": "code", 332 | "execution_count": 22, 333 | "id": "9482ffa2-105a-4677-8079-60c7c0b12a83", 334 | "metadata": {}, 335 | "outputs": [ 336 | { 337 | "data": { 338 | "text/plain": [ 339 | "{'sara': 92.0, 'sophia': 97.0}" 340 | ] 341 | }, 342 | "execution_count": 22, 343 | "metadata": {}, 344 | "output_type": "execute_result" 345 | } 346 | ], 347 | "source": [ 348 | "avg_score(sara=[92, 86, 98], sophia=[99, 97, 95])" 349 | ] 350 | }, 351 | { 352 | "cell_type": "markdown", 353 | "id": "12bf044b-d904-49c2-b4df-2d0f5f584cf5", 354 | "metadata": { 355 | "jp-MarkdownHeadingCollapsed": true, 356 | "tags": [] 357 | }, 358 | "source": [ 359 | "## 🔸 **lambda**" 360 | ] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "id": "1a2d623b-e240-43ab-8fe3-e13233561b46", 365 | "metadata": {}, 366 | "source": [ 367 | "\"string" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 4, 373 | "id": "25651e22-e486-4abf-852c-759486d12344", 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/plain": [ 379 | "(x)>" 380 | ] 381 | }, 382 | "execution_count": 4, 383 | "metadata": {}, 384 | "output_type": "execute_result" 385 | } 386 | ], 387 | "source": [ 388 | "avg_func = lambda x: sum(x)/len(x)\n", 389 | "avg_func" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "execution_count": 5, 395 | "id": "e45e414c-d670-4d63-91f0-2511bce156a5", 396 | "metadata": {}, 397 | "outputs": [ 398 | { 399 | "name": "stdout", 400 | "output_type": "stream", 401 | "text": [ 402 | "[97.0, 93.0, 79.5]\n" 403 | ] 404 | } 405 | ], 406 | "source": [ 407 | "grades = [[98, 96], [97, 89], [75, 84]]\n", 408 | "avg = []\n", 409 | "for g in grades:\n", 410 | " avg.append(avg_func(g))\n", 411 | "print(avg) " 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": 16, 417 | "id": "cc29d510-cbaa-4d51-8fa0-45cbde5dcc2b", 418 | "metadata": {}, 419 | "outputs": [ 420 | { 421 | "data": { 422 | "text/plain": [ 423 | "{'bahram': 97.0, 'shahram': 93.0, 'mahnam': 79.5}" 424 | ] 425 | }, 426 | "execution_count": 16, 427 | "metadata": {}, 428 | "output_type": "execute_result" 429 | } 430 | ], 431 | "source": [ 432 | "grades = {'bahram':[98, 96], 'shahram':[97, 89], 'mahnam':[75, 84]}\n", 433 | "\n", 434 | "avg_func = lambda inp: {k: sum(v)/len(v) for k, v in inp.items()}\n", 435 | "avg_func(grades)" 436 | ] 437 | }, 438 | { 439 | "cell_type": "markdown", 440 | "id": "2fbc422a-7883-4069-9951-aa0fca99c420", 441 | "metadata": { 442 | "jp-MarkdownHeadingCollapsed": true, 443 | "tags": [] 444 | }, 445 | "source": [ 446 | "## **✍️ Example 1: Prime numbers**" 447 | ] 448 | }, 449 | { 450 | "cell_type": "markdown", 451 | "id": "f844e430-c9cf-4cbd-a83c-165d703765ab", 452 | "metadata": {}, 453 | "source": [ 454 | "\"string" 455 | ] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "execution_count": 17, 460 | "id": "8c441d8c-50d1-483b-9606-3023bbfc914a", 461 | "metadata": {}, 462 | "outputs": [], 463 | "source": [ 464 | "def prime(n):\n", 465 | " message = 'This is a prime number.'\n", 466 | " for i in range(2, n):\n", 467 | " if n%i == 0:\n", 468 | " message = 'This is not a prime number!'\n", 469 | " break\n", 470 | " print(message)" 471 | ] 472 | }, 473 | { 474 | "cell_type": "code", 475 | "execution_count": 19, 476 | "id": "4cd6e6ab-fdee-4b1e-91dd-2dd40925f161", 477 | "metadata": {}, 478 | "outputs": [ 479 | { 480 | "name": "stdout", 481 | "output_type": "stream", 482 | "text": [ 483 | "This is not a prime number!\n" 484 | ] 485 | } 486 | ], 487 | "source": [ 488 | "prime(8)" 489 | ] 490 | }, 491 | { 492 | "cell_type": "markdown", 493 | "id": "811ab41c-9cf0-4146-9720-a2b96bffe9ae", 494 | "metadata": { 495 | "jp-MarkdownHeadingCollapsed": true, 496 | "tags": [] 497 | }, 498 | "source": [ 499 | "## **✍️ Example 2: Factorial function**" 500 | ] 501 | }, 502 | { 503 | "cell_type": "markdown", 504 | "id": "81859d69-d15a-4a81-9bbb-85d2bcde2145", 505 | "metadata": {}, 506 | "source": [ 507 | "\"string" 508 | ] 509 | }, 510 | { 511 | "cell_type": "code", 512 | "execution_count": 33, 513 | "id": "93517913-2b80-472b-a90e-55bfe43292c1", 514 | "metadata": { 515 | "id": "neIECYQAjMs4" 516 | }, 517 | "outputs": [], 518 | "source": [ 519 | "def factorial(numf):\n", 520 | " z = 1\n", 521 | " while numf > 0:\n", 522 | " z *= numf\n", 523 | " numf -= 1\n", 524 | " return z" 525 | ] 526 | }, 527 | { 528 | "cell_type": "code", 529 | "execution_count": 36, 530 | "id": "4ab84380-0ff8-414c-8e05-e67e030d1d3c", 531 | "metadata": { 532 | "colab": { 533 | "base_uri": "https://localhost:8080/" 534 | }, 535 | "id": "B7w29lQYjo5U", 536 | "outputId": "360326dd-7f26-4d64-87af-aa2fcb02993b" 537 | }, 538 | "outputs": [ 539 | { 540 | "name": "stdout", 541 | "output_type": "stream", 542 | "text": [ 543 | "120\n" 544 | ] 545 | } 546 | ], 547 | "source": [ 548 | "output = factorial(5)\n", 549 | "print(output)" 550 | ] 551 | }, 552 | { 553 | "cell_type": "markdown", 554 | "id": "9c937070-e287-4c3f-8d54-22f260e3b3cd", 555 | "metadata": { 556 | "jp-MarkdownHeadingCollapsed": true, 557 | "tags": [] 558 | }, 559 | "source": [ 560 | "## **✍️ Example 3: Fibonacci function**" 561 | ] 562 | }, 563 | { 564 | "cell_type": "markdown", 565 | "id": "be14e8ef-7ad1-4ffc-930a-0cfd350b140d", 566 | "metadata": {}, 567 | "source": [ 568 | "\"string" 569 | ] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "execution_count": 37, 574 | "id": "7d38d2c6-ed82-4190-9437-acc538039554", 575 | "metadata": {}, 576 | "outputs": [], 577 | "source": [ 578 | "def fibonacci(n):\n", 579 | " num1, num2 = 0, 1\n", 580 | " nums = []\n", 581 | " while 1:\n", 582 | " # print(num1, end=\" \")\n", 583 | " res = num1 + num2\n", 584 | " nums.append(num1)\n", 585 | " # update values\n", 586 | " num1 = num2\n", 587 | " num2 = res\n", 588 | " if num2 > n:\n", 589 | " break\n", 590 | " return nums" 591 | ] 592 | }, 593 | { 594 | "cell_type": "code", 595 | "execution_count": 38, 596 | "id": "76c2a3d0-129c-4870-9ae1-1407b9962c9d", 597 | "metadata": {}, 598 | "outputs": [ 599 | { 600 | "data": { 601 | "text/plain": [ 602 | "[0, 1, 1, 2, 3, 5]" 603 | ] 604 | }, 605 | "execution_count": 38, 606 | "metadata": {}, 607 | "output_type": "execute_result" 608 | } 609 | ], 610 | "source": [ 611 | "fibonacci(10)" 612 | ] 613 | }, 614 | { 615 | "cell_type": "markdown", 616 | "id": "3623f567-eb45-4af8-9737-cafecad002db", 617 | "metadata": { 618 | "jp-MarkdownHeadingCollapsed": true, 619 | "tags": [] 620 | }, 621 | "source": [ 622 | "## **✍️ Example 4: Palindrome**" 623 | ] 624 | }, 625 | { 626 | "cell_type": "markdown", 627 | "id": "2bb1411e-718a-4a4f-868e-fc9df2290b65", 628 | "metadata": {}, 629 | "source": [ 630 | "\"string" 631 | ] 632 | }, 633 | { 634 | "cell_type": "code", 635 | "execution_count": 22, 636 | "id": "b7d09b35-8970-41ac-ab5f-2470bd74a4b6", 637 | "metadata": {}, 638 | "outputs": [], 639 | "source": [ 640 | "def palindrome(txt):\n", 641 | " if txt.lower() == txt.lower()[::-1]:\n", 642 | " print('This word is palindrome!')\n", 643 | " else:\n", 644 | " print('This word is NOT palindrome!')" 645 | ] 646 | }, 647 | { 648 | "cell_type": "code", 649 | "execution_count": 23, 650 | "id": "5dd7b241-e531-4df7-a5dd-e9f953a6703d", 651 | "metadata": {}, 652 | "outputs": [ 653 | { 654 | "name": "stdout", 655 | "output_type": "stream", 656 | "text": [ 657 | "This word is palindrome!\n" 658 | ] 659 | } 660 | ], 661 | "source": [ 662 | "palindrome('hih')" 663 | ] 664 | } 665 | ], 666 | "metadata": { 667 | "kernelspec": { 668 | "display_name": "Python 3 (ipykernel)", 669 | "language": "python", 670 | "name": "python3" 671 | }, 672 | "language_info": { 673 | "codemirror_mode": { 674 | "name": "ipython", 675 | "version": 3 676 | }, 677 | "file_extension": ".py", 678 | "mimetype": "text/x-python", 679 | "name": "python", 680 | "nbconvert_exporter": "python", 681 | "pygments_lexer": "ipython3", 682 | "version": "3.9.12" 683 | } 684 | }, 685 | "nbformat": 4, 686 | "nbformat_minor": 5 687 | } 688 | -------------------------------------------------------------------------------- /python/lectures/section-2-operators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b5a35374-73fa-40c4-a707-ec33ea846df3", 6 | "metadata": { 7 | "id": "pbxR79EUAYW_", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 2: Operators 🧮**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "id": "a93d4c70-96d2-4052-a2b2-091311617d27", 18 | "metadata": { 19 | "id": "gohcMHEfHNZe" 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "a = 5\n", 24 | "b = 2" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "id": "a230c9fa-0f85-439f-a296-f19e1578cfa2", 30 | "metadata": { 31 | "tags": [] 32 | }, 33 | "source": [ 34 | "## **🔸 Mathematical Operations**" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "id": "ba43a7c7-d556-4f9b-8099-58585b922b6a", 40 | "metadata": { 41 | "tags": [] 42 | }, 43 | "source": [ 44 | "### addition" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 8, 50 | "id": "c41296ef-70bf-4708-ac36-84cc005270e8", 51 | "metadata": { 52 | "colab": { 53 | "base_uri": "https://localhost:8080/" 54 | }, 55 | "id": "kd3GTU8ZHUS9", 56 | "outputId": "f1465461-9e65-4d60-d788-34bf318daf8f" 57 | }, 58 | "outputs": [ 59 | { 60 | "data": { 61 | "text/plain": [ 62 | "1" 63 | ] 64 | }, 65 | "execution_count": 8, 66 | "metadata": {}, 67 | "output_type": "execute_result" 68 | } 69 | ], 70 | "source": [ 71 | "c = a + b\n", 72 | "c\n", 73 | "\n", 74 | "d = 'sal'\n", 75 | "e = 'am'\n", 76 | "d + e\n", 77 | "\n", 78 | "f = True\n", 79 | "g = False\n", 80 | "f + g\n", 81 | "\n", 82 | "# a + d" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "id": "32efb18e-2397-47fb-9c64-8165e9a057c3", 88 | "metadata": { 89 | "tags": [] 90 | }, 91 | "source": [ 92 | "### subtraction " 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 9, 98 | "id": "ca64bd78-06bc-4309-9811-3709d7ad5c99", 99 | "metadata": { 100 | "colab": { 101 | "base_uri": "https://localhost:8080/" 102 | }, 103 | "id": "TcNxhrC6Hbhv", 104 | "outputId": "9f3f3bad-888e-4eae-c02c-2951813c3343" 105 | }, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "3" 111 | ] 112 | }, 113 | "execution_count": 9, 114 | "metadata": {}, 115 | "output_type": "execute_result" 116 | } 117 | ], 118 | "source": [ 119 | "a - b" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "id": "efce5c08-3808-48b6-9974-25594af67b7d", 125 | "metadata": { 126 | "tags": [] 127 | }, 128 | "source": [ 129 | "### multiplication " 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 10, 135 | "id": "8df81297-ddcb-4b44-af27-e2c16f4acc07", 136 | "metadata": { 137 | "colab": { 138 | "base_uri": "https://localhost:8080/" 139 | }, 140 | "id": "H_RzhG4NHhWb", 141 | "outputId": "16edb425-b047-4cb9-cc57-d2c471bbec41" 142 | }, 143 | "outputs": [ 144 | { 145 | "data": { 146 | "text/plain": [ 147 | "10" 148 | ] 149 | }, 150 | "execution_count": 10, 151 | "metadata": {}, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "a * b" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "id": "32506a29-f164-4e68-816f-66838ea25f4d", 162 | "metadata": { 163 | "tags": [] 164 | }, 165 | "source": [ 166 | "### division" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 11, 172 | "id": "b210a2eb-de0a-4b66-a7ac-d58c21c9e67f", 173 | "metadata": { 174 | "colab": { 175 | "base_uri": "https://localhost:8080/" 176 | }, 177 | "id": "ef_SJvdfHmsh", 178 | "outputId": "539bb96b-72eb-461a-f6a9-46f02d322b32" 179 | }, 180 | "outputs": [ 181 | { 182 | "data": { 183 | "text/plain": [ 184 | "2.5" 185 | ] 186 | }, 187 | "execution_count": 11, 188 | "metadata": {}, 189 | "output_type": "execute_result" 190 | } 191 | ], 192 | "source": [ 193 | "a / b" 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "id": "b101ca52-250a-4006-87f8-203acbee0458", 199 | "metadata": { 200 | "tags": [] 201 | }, 202 | "source": [ 203 | "### power" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 13, 209 | "id": "c307a80a-e6c8-4cde-8a44-98a671c6c40b", 210 | "metadata": { 211 | "colab": { 212 | "base_uri": "https://localhost:8080/" 213 | }, 214 | "id": "5p4Of7z9HsRZ", 215 | "outputId": "19856f33-6bb3-4a86-d437-53936ad6ec98" 216 | }, 217 | "outputs": [ 218 | { 219 | "data": { 220 | "text/plain": [ 221 | "(25, 2.23606797749979)" 222 | ] 223 | }, 224 | "execution_count": 13, 225 | "metadata": {}, 226 | "output_type": "execute_result" 227 | } 228 | ], 229 | "source": [ 230 | "a**b, a**0.5" 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "id": "78b0c451-31c7-4bdb-8fe0-df168375927f", 236 | "metadata": { 237 | "tags": [] 238 | }, 239 | "source": [ 240 | "### remainder" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 14, 246 | "id": "7cd865f0-ef00-45b5-b695-7826c7413a37", 247 | "metadata": { 248 | "colab": { 249 | "base_uri": "https://localhost:8080/" 250 | }, 251 | "id": "ndDH0LMhH5pU", 252 | "outputId": "e09161a8-86fb-4955-d743-2bc77a234465" 253 | }, 254 | "outputs": [ 255 | { 256 | "data": { 257 | "text/plain": [ 258 | "1" 259 | ] 260 | }, 261 | "execution_count": 14, 262 | "metadata": {}, 263 | "output_type": "execute_result" 264 | } 265 | ], 266 | "source": [ 267 | "a % b" 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "id": "bb8bd663-7608-41bc-8eb0-ba79ec292c62", 273 | "metadata": { 274 | "tags": [] 275 | }, 276 | "source": [ 277 | "### quo" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": 16, 283 | "id": "46943007-27e1-48d7-9e3c-6ad83d2c67f5", 284 | "metadata": { 285 | "colab": { 286 | "base_uri": "https://localhost:8080/" 287 | }, 288 | "id": "Gx4lscvsIA3O", 289 | "outputId": "2f4e242e-a023-4d84-da3a-f522c2efe866" 290 | }, 291 | "outputs": [ 292 | { 293 | "data": { 294 | "text/plain": [ 295 | "3" 296 | ] 297 | }, 298 | "execution_count": 16, 299 | "metadata": {}, 300 | "output_type": "execute_result" 301 | } 302 | ], 303 | "source": [ 304 | "a // b" 305 | ] 306 | }, 307 | { 308 | "cell_type": "markdown", 309 | "id": "87dbdd5b-13a3-4118-b8d0-9882241991df", 310 | "metadata": { 311 | "tags": [] 312 | }, 313 | "source": [ 314 | "## **🔸 Operators Precedence**" 315 | ] 316 | }, 317 | { 318 | "cell_type": "markdown", 319 | "id": "55fddd5a-c68d-4b7d-8394-4ede83f26018", 320 | "metadata": {}, 321 | "source": [ 322 | "\"string" 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": 26, 328 | "id": "915dd4a4-bacc-470a-9b5e-3336da477cbd", 329 | "metadata": {}, 330 | "outputs": [ 331 | { 332 | "data": { 333 | "text/plain": [ 334 | "19" 335 | ] 336 | }, 337 | "execution_count": 26, 338 | "metadata": {}, 339 | "output_type": "execute_result" 340 | } 341 | ], 342 | "source": [ 343 | "(-3+5)**2+3*(4+1) " 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 24, 349 | "id": "7d35e47c-caf0-4fa2-8ffb-2ed1495ed473", 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "data": { 354 | "text/plain": [ 355 | "-13" 356 | ] 357 | }, 358 | "execution_count": 24, 359 | "metadata": {}, 360 | "output_type": "execute_result" 361 | } 362 | ], 363 | "source": [ 364 | "a = -3**2*4+23" 365 | ] 366 | }, 367 | { 368 | "cell_type": "markdown", 369 | "id": "ad7260f2-3f99-4e30-a8c2-1f7c6d27eb43", 370 | "metadata": { 371 | "id": "w1bdIbUgIP8q", 372 | "tags": [] 373 | }, 374 | "source": [ 375 | "## **🔸 Assignment operators**" 376 | ] 377 | }, 378 | { 379 | "cell_type": "markdown", 380 | "id": "a4245fc4-b3ca-4ac6-9bd8-ed400933fece", 381 | "metadata": { 382 | "tags": [] 383 | }, 384 | "source": [ 385 | "### Simple assignment operator" 386 | ] 387 | }, 388 | { 389 | "cell_type": "code", 390 | "execution_count": 37, 391 | "id": "8809c0a5-bdc8-4f44-8585-dfafb8b88d22", 392 | "metadata": { 393 | "colab": { 394 | "base_uri": "https://localhost:8080/" 395 | }, 396 | "id": "VKF7oPlaIWBt", 397 | "outputId": "7089a9e1-85a1-4b67-f3e0-c85fcd1b3be3" 398 | }, 399 | "outputs": [ 400 | { 401 | "data": { 402 | "text/plain": [ 403 | "5" 404 | ] 405 | }, 406 | "execution_count": 37, 407 | "metadata": {}, 408 | "output_type": "execute_result" 409 | } 410 | ], 411 | "source": [ 412 | "a = a - 1\n", 413 | "a" 414 | ] 415 | }, 416 | { 417 | "cell_type": "markdown", 418 | "id": "27c01bc3-85f0-4e23-99fb-0b89fbee600b", 419 | "metadata": { 420 | "tags": [] 421 | }, 422 | "source": [ 423 | "### Add and equal operator" 424 | ] 425 | }, 426 | { 427 | "cell_type": "code", 428 | "execution_count": 43, 429 | "id": "76695033-8667-4e76-b6f6-9ccfef54872e", 430 | "metadata": { 431 | "colab": { 432 | "base_uri": "https://localhost:8080/" 433 | }, 434 | "id": "qkhXfdZFIgaT", 435 | "outputId": "ac9fbbeb-b80c-465c-c93c-8fbaeecb74ba" 436 | }, 437 | "outputs": [ 438 | { 439 | "data": { 440 | "text/plain": [ 441 | "11" 442 | ] 443 | }, 444 | "execution_count": 43, 445 | "metadata": {}, 446 | "output_type": "execute_result" 447 | } 448 | ], 449 | "source": [ 450 | "a += 1\n", 451 | "a" 452 | ] 453 | }, 454 | { 455 | "cell_type": "markdown", 456 | "id": "1f07173a-aa7e-4080-9099-fe923ea8ceb9", 457 | "metadata": { 458 | "tags": [] 459 | }, 460 | "source": [ 461 | "### Subtract and equal operator" 462 | ] 463 | }, 464 | { 465 | "cell_type": "code", 466 | "execution_count": 59, 467 | "id": "0dde5a9b-8f4c-48ec-a3c0-13a74c113161", 468 | "metadata": { 469 | "colab": { 470 | "base_uri": "https://localhost:8080/" 471 | }, 472 | "id": "ksnetuV9IvW-", 473 | "outputId": "1435dbb2-5c6b-4a9b-ef8b-45fef2faee4b" 474 | }, 475 | "outputs": [ 476 | { 477 | "data": { 478 | "text/plain": [ 479 | "7375" 480 | ] 481 | }, 482 | "execution_count": 59, 483 | "metadata": {}, 484 | "output_type": "execute_result" 485 | } 486 | ], 487 | "source": [ 488 | "a -= b\n", 489 | "b -= a\n", 490 | "a" 491 | ] 492 | }, 493 | { 494 | "cell_type": "markdown", 495 | "id": "1debcb1f-746f-4b75-b033-80d1e48f35c7", 496 | "metadata": { 497 | "tags": [] 498 | }, 499 | "source": [ 500 | "### Multiply and equal operator" 501 | ] 502 | }, 503 | { 504 | "cell_type": "code", 505 | "execution_count": 67, 506 | "id": "6800466a-05f7-41c3-8912-198a3a8c7de4", 507 | "metadata": { 508 | "colab": { 509 | "base_uri": "https://localhost:8080/" 510 | }, 511 | "id": "w5p1yKFJIqOu", 512 | "outputId": "7ad35685-a460-4d8b-ac48-e79de4959290" 513 | }, 514 | "outputs": [ 515 | { 516 | "data": { 517 | "text/plain": [ 518 | "256" 519 | ] 520 | }, 521 | "execution_count": 67, 522 | "metadata": {}, 523 | "output_type": "execute_result" 524 | } 525 | ], 526 | "source": [ 527 | "a *= 2\n", 528 | "a" 529 | ] 530 | }, 531 | { 532 | "cell_type": "markdown", 533 | "id": "d3c3b869-9d80-4089-af0f-6bf33fc5eded", 534 | "metadata": { 535 | "tags": [] 536 | }, 537 | "source": [ 538 | "### Divide and equal operator" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 72, 544 | "id": "17653001-b8ba-4902-a9ca-8b9efe91538c", 545 | "metadata": { 546 | "colab": { 547 | "base_uri": "https://localhost:8080/" 548 | }, 549 | "id": "TpyFapIaI06D", 550 | "outputId": "f17fef4c-013e-4cd5-fc29-8c106e5a78ff" 551 | }, 552 | "outputs": [ 553 | { 554 | "data": { 555 | "text/plain": [ 556 | "-1.0580148471112777e-18" 557 | ] 558 | }, 559 | "execution_count": 72, 560 | "metadata": {}, 561 | "output_type": "execute_result" 562 | } 563 | ], 564 | "source": [ 565 | "a /= b\n", 566 | "a" 567 | ] 568 | }, 569 | { 570 | "cell_type": "code", 571 | "execution_count": 75, 572 | "id": "9db1014e-b862-4605-a1fd-ef096385b81d", 573 | "metadata": {}, 574 | "outputs": [ 575 | { 576 | "data": { 577 | "text/plain": [ 578 | "12" 579 | ] 580 | }, 581 | "execution_count": 75, 582 | "metadata": {}, 583 | "output_type": "execute_result" 584 | } 585 | ], 586 | "source": [ 587 | "a = 1\n", 588 | "a *= 2**3+4\n", 589 | "a" 590 | ] 591 | }, 592 | { 593 | "cell_type": "code", 594 | "execution_count": 76, 595 | "id": "cb4a6b63-c35a-4b56-b04a-534ec8618e06", 596 | "metadata": {}, 597 | "outputs": [ 598 | { 599 | "data": { 600 | "text/plain": [ 601 | "25" 602 | ] 603 | }, 604 | "execution_count": 76, 605 | "metadata": {}, 606 | "output_type": "execute_result" 607 | } 608 | ], 609 | "source": [ 610 | "r = 5\n", 611 | "r **= 2\n", 612 | "r" 613 | ] 614 | }, 615 | { 616 | "cell_type": "markdown", 617 | "id": "d7fefbbf-d800-4e40-ad45-2c0d5991298e", 618 | "metadata": { 619 | "tags": [] 620 | }, 621 | "source": [ 622 | "## **✍️ Example 1: volume of a cylinder**" 623 | ] 624 | }, 625 | { 626 | "cell_type": "markdown", 627 | "id": "f2cf3154-3398-4ca0-97ab-13e1d3e34450", 628 | "metadata": {}, 629 | "source": [ 630 | "\"string" 631 | ] 632 | }, 633 | { 634 | "cell_type": "code", 635 | "execution_count": 78, 636 | "id": "64072bde-0c17-4f97-9002-640b66c86984", 637 | "metadata": { 638 | "colab": { 639 | "base_uri": "https://localhost:8080/" 640 | }, 641 | "id": "Pkqhu4FWhSW1", 642 | "outputId": "6ebd4f1e-a4f3-4c55-fb17-c10708ed43a7" 643 | }, 644 | "outputs": [ 645 | { 646 | "data": { 647 | "text/plain": [ 648 | "785.3999999999999" 649 | ] 650 | }, 651 | "execution_count": 78, 652 | "metadata": {}, 653 | "output_type": "execute_result" 654 | } 655 | ], 656 | "source": [ 657 | "pi = 3.1416\n", 658 | "r = 5\n", 659 | "h = 10\n", 660 | "\n", 661 | "volume_cylinder = pi*r**2*h\n", 662 | "volume_cylinder" 663 | ] 664 | }, 665 | { 666 | "cell_type": "markdown", 667 | "id": "f903fe39-8106-4c39-a3ea-a8d4c70796c0", 668 | "metadata": { 669 | "id": "dc4_32i9arwQ", 670 | "tags": [] 671 | }, 672 | "source": [ 673 | "## **✍️ Example 2: BMI**" 674 | ] 675 | }, 676 | { 677 | "cell_type": "markdown", 678 | "id": "2da4e4d8-9eb5-4d61-919a-cf3eaab02283", 679 | "metadata": { 680 | "id": "2658TWO5ftjq" 681 | }, 682 | "source": [ 683 | "\"string" 684 | ] 685 | }, 686 | { 687 | "cell_type": "code", 688 | "execution_count": 79, 689 | "id": "26766ef3-1e0b-40d7-b86a-152da406995e", 690 | "metadata": {}, 691 | "outputs": [ 692 | { 693 | "data": { 694 | "text/plain": [ 695 | "24.691358024691358" 696 | ] 697 | }, 698 | "execution_count": 79, 699 | "metadata": {}, 700 | "output_type": "execute_result" 701 | } 702 | ], 703 | "source": [ 704 | "weight = 80.\n", 705 | "height = 1.8\n", 706 | "\n", 707 | "bmi = weight / height**2\n", 708 | "bmi" 709 | ] 710 | }, 711 | { 712 | "cell_type": "markdown", 713 | "id": "65641fa2-459f-4de4-a7bb-3746663725e3", 714 | "metadata": { 715 | "id": "dc4_32i9arwQ", 716 | "tags": [] 717 | }, 718 | "source": [ 719 | "## **✍️ Example 3: Gaussian**" 720 | ] 721 | }, 722 | { 723 | "cell_type": "markdown", 724 | "id": "af8e5884-0a00-43b3-8d5e-5d85de267b6d", 725 | "metadata": { 726 | "id": "2658TWO5ftjq" 727 | }, 728 | "source": [ 729 | "\"string" 730 | ] 731 | }, 732 | { 733 | "cell_type": "code", 734 | "execution_count": 87, 735 | "id": "89b56371-787e-4713-8a67-d7001ea6c25b", 736 | "metadata": {}, 737 | "outputs": [ 738 | { 739 | "data": { 740 | "text/plain": [ 741 | "0.054335240837381185" 742 | ] 743 | }, 744 | "execution_count": 87, 745 | "metadata": {}, 746 | "output_type": "execute_result" 747 | } 748 | ], 749 | "source": [ 750 | "m = 0\n", 751 | "x = 2\n", 752 | "s = 1\n", 753 | "exp = 2.71\n", 754 | "pi = 3.14\n", 755 | "\n", 756 | "gaussian = (1/(2*pi*s)**0.5) * exp**(-0.5*((x - m) / s)**2)\n", 757 | "gaussian" 758 | ] 759 | } 760 | ], 761 | "metadata": { 762 | "kernelspec": { 763 | "display_name": "Python 3 (ipykernel)", 764 | "language": "python", 765 | "name": "python3" 766 | }, 767 | "language_info": { 768 | "codemirror_mode": { 769 | "name": "ipython", 770 | "version": 3 771 | }, 772 | "file_extension": ".py", 773 | "mimetype": "text/x-python", 774 | "name": "python", 775 | "nbconvert_exporter": "python", 776 | "pygments_lexer": "ipython3", 777 | "version": "3.9.15" 778 | } 779 | }, 780 | "nbformat": 4, 781 | "nbformat_minor": 5 782 | } 783 | -------------------------------------------------------------------------------- /python/lectures/.ipynb_checkpoints/section-2-operators-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b5a35374-73fa-40c4-a707-ec33ea846df3", 6 | "metadata": { 7 | "id": "pbxR79EUAYW_", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 2: Operators 🧮**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "id": "a93d4c70-96d2-4052-a2b2-091311617d27", 18 | "metadata": { 19 | "id": "gohcMHEfHNZe" 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "a = 5\n", 24 | "b = 2" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "id": "a230c9fa-0f85-439f-a296-f19e1578cfa2", 30 | "metadata": { 31 | "tags": [] 32 | }, 33 | "source": [ 34 | "## **🔸 Mathematical Operations**" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "id": "ba43a7c7-d556-4f9b-8099-58585b922b6a", 40 | "metadata": { 41 | "tags": [] 42 | }, 43 | "source": [ 44 | "### addition" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 8, 50 | "id": "c41296ef-70bf-4708-ac36-84cc005270e8", 51 | "metadata": { 52 | "colab": { 53 | "base_uri": "https://localhost:8080/" 54 | }, 55 | "id": "kd3GTU8ZHUS9", 56 | "outputId": "f1465461-9e65-4d60-d788-34bf318daf8f" 57 | }, 58 | "outputs": [ 59 | { 60 | "data": { 61 | "text/plain": [ 62 | "1" 63 | ] 64 | }, 65 | "execution_count": 8, 66 | "metadata": {}, 67 | "output_type": "execute_result" 68 | } 69 | ], 70 | "source": [ 71 | "c = a + b\n", 72 | "c\n", 73 | "\n", 74 | "d = 'sal'\n", 75 | "e = 'am'\n", 76 | "d + e\n", 77 | "\n", 78 | "f = True\n", 79 | "g = False\n", 80 | "f + g\n", 81 | "\n", 82 | "# a + d" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "id": "32efb18e-2397-47fb-9c64-8165e9a057c3", 88 | "metadata": { 89 | "tags": [] 90 | }, 91 | "source": [ 92 | "### subtraction " 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 9, 98 | "id": "ca64bd78-06bc-4309-9811-3709d7ad5c99", 99 | "metadata": { 100 | "colab": { 101 | "base_uri": "https://localhost:8080/" 102 | }, 103 | "id": "TcNxhrC6Hbhv", 104 | "outputId": "9f3f3bad-888e-4eae-c02c-2951813c3343" 105 | }, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "3" 111 | ] 112 | }, 113 | "execution_count": 9, 114 | "metadata": {}, 115 | "output_type": "execute_result" 116 | } 117 | ], 118 | "source": [ 119 | "a - b" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "id": "efce5c08-3808-48b6-9974-25594af67b7d", 125 | "metadata": { 126 | "tags": [] 127 | }, 128 | "source": [ 129 | "### multiplication " 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 10, 135 | "id": "8df81297-ddcb-4b44-af27-e2c16f4acc07", 136 | "metadata": { 137 | "colab": { 138 | "base_uri": "https://localhost:8080/" 139 | }, 140 | "id": "H_RzhG4NHhWb", 141 | "outputId": "16edb425-b047-4cb9-cc57-d2c471bbec41" 142 | }, 143 | "outputs": [ 144 | { 145 | "data": { 146 | "text/plain": [ 147 | "10" 148 | ] 149 | }, 150 | "execution_count": 10, 151 | "metadata": {}, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "a * b" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "id": "32506a29-f164-4e68-816f-66838ea25f4d", 162 | "metadata": { 163 | "tags": [] 164 | }, 165 | "source": [ 166 | "### division" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 11, 172 | "id": "b210a2eb-de0a-4b66-a7ac-d58c21c9e67f", 173 | "metadata": { 174 | "colab": { 175 | "base_uri": "https://localhost:8080/" 176 | }, 177 | "id": "ef_SJvdfHmsh", 178 | "outputId": "539bb96b-72eb-461a-f6a9-46f02d322b32" 179 | }, 180 | "outputs": [ 181 | { 182 | "data": { 183 | "text/plain": [ 184 | "2.5" 185 | ] 186 | }, 187 | "execution_count": 11, 188 | "metadata": {}, 189 | "output_type": "execute_result" 190 | } 191 | ], 192 | "source": [ 193 | "a / b" 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "id": "b101ca52-250a-4006-87f8-203acbee0458", 199 | "metadata": { 200 | "tags": [] 201 | }, 202 | "source": [ 203 | "### power" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 13, 209 | "id": "c307a80a-e6c8-4cde-8a44-98a671c6c40b", 210 | "metadata": { 211 | "colab": { 212 | "base_uri": "https://localhost:8080/" 213 | }, 214 | "id": "5p4Of7z9HsRZ", 215 | "outputId": "19856f33-6bb3-4a86-d437-53936ad6ec98" 216 | }, 217 | "outputs": [ 218 | { 219 | "data": { 220 | "text/plain": [ 221 | "(25, 2.23606797749979)" 222 | ] 223 | }, 224 | "execution_count": 13, 225 | "metadata": {}, 226 | "output_type": "execute_result" 227 | } 228 | ], 229 | "source": [ 230 | "a**b, a**0.5" 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "id": "78b0c451-31c7-4bdb-8fe0-df168375927f", 236 | "metadata": { 237 | "tags": [] 238 | }, 239 | "source": [ 240 | "### remainder" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 14, 246 | "id": "7cd865f0-ef00-45b5-b695-7826c7413a37", 247 | "metadata": { 248 | "colab": { 249 | "base_uri": "https://localhost:8080/" 250 | }, 251 | "id": "ndDH0LMhH5pU", 252 | "outputId": "e09161a8-86fb-4955-d743-2bc77a234465" 253 | }, 254 | "outputs": [ 255 | { 256 | "data": { 257 | "text/plain": [ 258 | "1" 259 | ] 260 | }, 261 | "execution_count": 14, 262 | "metadata": {}, 263 | "output_type": "execute_result" 264 | } 265 | ], 266 | "source": [ 267 | "a % b" 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "id": "bb8bd663-7608-41bc-8eb0-ba79ec292c62", 273 | "metadata": { 274 | "tags": [] 275 | }, 276 | "source": [ 277 | "### quo" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": 16, 283 | "id": "46943007-27e1-48d7-9e3c-6ad83d2c67f5", 284 | "metadata": { 285 | "colab": { 286 | "base_uri": "https://localhost:8080/" 287 | }, 288 | "id": "Gx4lscvsIA3O", 289 | "outputId": "2f4e242e-a023-4d84-da3a-f522c2efe866" 290 | }, 291 | "outputs": [ 292 | { 293 | "data": { 294 | "text/plain": [ 295 | "3" 296 | ] 297 | }, 298 | "execution_count": 16, 299 | "metadata": {}, 300 | "output_type": "execute_result" 301 | } 302 | ], 303 | "source": [ 304 | "a // b" 305 | ] 306 | }, 307 | { 308 | "cell_type": "markdown", 309 | "id": "87dbdd5b-13a3-4118-b8d0-9882241991df", 310 | "metadata": { 311 | "tags": [] 312 | }, 313 | "source": [ 314 | "## **🔸 Operators Precedence**" 315 | ] 316 | }, 317 | { 318 | "cell_type": "markdown", 319 | "id": "55fddd5a-c68d-4b7d-8394-4ede83f26018", 320 | "metadata": {}, 321 | "source": [ 322 | "\"string" 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": 26, 328 | "id": "915dd4a4-bacc-470a-9b5e-3336da477cbd", 329 | "metadata": {}, 330 | "outputs": [ 331 | { 332 | "data": { 333 | "text/plain": [ 334 | "19" 335 | ] 336 | }, 337 | "execution_count": 26, 338 | "metadata": {}, 339 | "output_type": "execute_result" 340 | } 341 | ], 342 | "source": [ 343 | "(-3+5)**2+3*(4+1) " 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 24, 349 | "id": "7d35e47c-caf0-4fa2-8ffb-2ed1495ed473", 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "data": { 354 | "text/plain": [ 355 | "-13" 356 | ] 357 | }, 358 | "execution_count": 24, 359 | "metadata": {}, 360 | "output_type": "execute_result" 361 | } 362 | ], 363 | "source": [ 364 | "a = -3**2*4+23" 365 | ] 366 | }, 367 | { 368 | "cell_type": "markdown", 369 | "id": "ad7260f2-3f99-4e30-a8c2-1f7c6d27eb43", 370 | "metadata": { 371 | "id": "w1bdIbUgIP8q", 372 | "tags": [] 373 | }, 374 | "source": [ 375 | "## **🔸 Assignment operators**" 376 | ] 377 | }, 378 | { 379 | "cell_type": "markdown", 380 | "id": "a4245fc4-b3ca-4ac6-9bd8-ed400933fece", 381 | "metadata": { 382 | "tags": [] 383 | }, 384 | "source": [ 385 | "### Simple assignment operator" 386 | ] 387 | }, 388 | { 389 | "cell_type": "code", 390 | "execution_count": 37, 391 | "id": "8809c0a5-bdc8-4f44-8585-dfafb8b88d22", 392 | "metadata": { 393 | "colab": { 394 | "base_uri": "https://localhost:8080/" 395 | }, 396 | "id": "VKF7oPlaIWBt", 397 | "outputId": "7089a9e1-85a1-4b67-f3e0-c85fcd1b3be3" 398 | }, 399 | "outputs": [ 400 | { 401 | "data": { 402 | "text/plain": [ 403 | "5" 404 | ] 405 | }, 406 | "execution_count": 37, 407 | "metadata": {}, 408 | "output_type": "execute_result" 409 | } 410 | ], 411 | "source": [ 412 | "a = a - 1\n", 413 | "a" 414 | ] 415 | }, 416 | { 417 | "cell_type": "markdown", 418 | "id": "27c01bc3-85f0-4e23-99fb-0b89fbee600b", 419 | "metadata": { 420 | "tags": [] 421 | }, 422 | "source": [ 423 | "### Add and equal operator" 424 | ] 425 | }, 426 | { 427 | "cell_type": "code", 428 | "execution_count": 43, 429 | "id": "76695033-8667-4e76-b6f6-9ccfef54872e", 430 | "metadata": { 431 | "colab": { 432 | "base_uri": "https://localhost:8080/" 433 | }, 434 | "id": "qkhXfdZFIgaT", 435 | "outputId": "ac9fbbeb-b80c-465c-c93c-8fbaeecb74ba" 436 | }, 437 | "outputs": [ 438 | { 439 | "data": { 440 | "text/plain": [ 441 | "11" 442 | ] 443 | }, 444 | "execution_count": 43, 445 | "metadata": {}, 446 | "output_type": "execute_result" 447 | } 448 | ], 449 | "source": [ 450 | "a += 1\n", 451 | "a" 452 | ] 453 | }, 454 | { 455 | "cell_type": "markdown", 456 | "id": "1f07173a-aa7e-4080-9099-fe923ea8ceb9", 457 | "metadata": { 458 | "tags": [] 459 | }, 460 | "source": [ 461 | "### Subtract and equal operator" 462 | ] 463 | }, 464 | { 465 | "cell_type": "code", 466 | "execution_count": 59, 467 | "id": "0dde5a9b-8f4c-48ec-a3c0-13a74c113161", 468 | "metadata": { 469 | "colab": { 470 | "base_uri": "https://localhost:8080/" 471 | }, 472 | "id": "ksnetuV9IvW-", 473 | "outputId": "1435dbb2-5c6b-4a9b-ef8b-45fef2faee4b" 474 | }, 475 | "outputs": [ 476 | { 477 | "data": { 478 | "text/plain": [ 479 | "7375" 480 | ] 481 | }, 482 | "execution_count": 59, 483 | "metadata": {}, 484 | "output_type": "execute_result" 485 | } 486 | ], 487 | "source": [ 488 | "a -= b\n", 489 | "b -= a\n", 490 | "a" 491 | ] 492 | }, 493 | { 494 | "cell_type": "markdown", 495 | "id": "1debcb1f-746f-4b75-b033-80d1e48f35c7", 496 | "metadata": { 497 | "tags": [] 498 | }, 499 | "source": [ 500 | "### Multiply and equal operator" 501 | ] 502 | }, 503 | { 504 | "cell_type": "code", 505 | "execution_count": 67, 506 | "id": "6800466a-05f7-41c3-8912-198a3a8c7de4", 507 | "metadata": { 508 | "colab": { 509 | "base_uri": "https://localhost:8080/" 510 | }, 511 | "id": "w5p1yKFJIqOu", 512 | "outputId": "7ad35685-a460-4d8b-ac48-e79de4959290" 513 | }, 514 | "outputs": [ 515 | { 516 | "data": { 517 | "text/plain": [ 518 | "256" 519 | ] 520 | }, 521 | "execution_count": 67, 522 | "metadata": {}, 523 | "output_type": "execute_result" 524 | } 525 | ], 526 | "source": [ 527 | "a *= 2\n", 528 | "a" 529 | ] 530 | }, 531 | { 532 | "cell_type": "markdown", 533 | "id": "d3c3b869-9d80-4089-af0f-6bf33fc5eded", 534 | "metadata": { 535 | "tags": [] 536 | }, 537 | "source": [ 538 | "### Divide and equal operator" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 72, 544 | "id": "17653001-b8ba-4902-a9ca-8b9efe91538c", 545 | "metadata": { 546 | "colab": { 547 | "base_uri": "https://localhost:8080/" 548 | }, 549 | "id": "TpyFapIaI06D", 550 | "outputId": "f17fef4c-013e-4cd5-fc29-8c106e5a78ff" 551 | }, 552 | "outputs": [ 553 | { 554 | "data": { 555 | "text/plain": [ 556 | "-1.0580148471112777e-18" 557 | ] 558 | }, 559 | "execution_count": 72, 560 | "metadata": {}, 561 | "output_type": "execute_result" 562 | } 563 | ], 564 | "source": [ 565 | "a /= b\n", 566 | "a" 567 | ] 568 | }, 569 | { 570 | "cell_type": "code", 571 | "execution_count": 75, 572 | "id": "9db1014e-b862-4605-a1fd-ef096385b81d", 573 | "metadata": {}, 574 | "outputs": [ 575 | { 576 | "data": { 577 | "text/plain": [ 578 | "12" 579 | ] 580 | }, 581 | "execution_count": 75, 582 | "metadata": {}, 583 | "output_type": "execute_result" 584 | } 585 | ], 586 | "source": [ 587 | "a = 1\n", 588 | "a *= 2**3+4\n", 589 | "a" 590 | ] 591 | }, 592 | { 593 | "cell_type": "code", 594 | "execution_count": 76, 595 | "id": "cb4a6b63-c35a-4b56-b04a-534ec8618e06", 596 | "metadata": {}, 597 | "outputs": [ 598 | { 599 | "data": { 600 | "text/plain": [ 601 | "25" 602 | ] 603 | }, 604 | "execution_count": 76, 605 | "metadata": {}, 606 | "output_type": "execute_result" 607 | } 608 | ], 609 | "source": [ 610 | "r = 5\n", 611 | "r **= 2\n", 612 | "r" 613 | ] 614 | }, 615 | { 616 | "cell_type": "markdown", 617 | "id": "d7fefbbf-d800-4e40-ad45-2c0d5991298e", 618 | "metadata": { 619 | "tags": [] 620 | }, 621 | "source": [ 622 | "## **✍️ Example 1: volume of a cylinder**" 623 | ] 624 | }, 625 | { 626 | "cell_type": "markdown", 627 | "id": "f2cf3154-3398-4ca0-97ab-13e1d3e34450", 628 | "metadata": {}, 629 | "source": [ 630 | "\"string" 631 | ] 632 | }, 633 | { 634 | "cell_type": "code", 635 | "execution_count": 78, 636 | "id": "64072bde-0c17-4f97-9002-640b66c86984", 637 | "metadata": { 638 | "colab": { 639 | "base_uri": "https://localhost:8080/" 640 | }, 641 | "id": "Pkqhu4FWhSW1", 642 | "outputId": "6ebd4f1e-a4f3-4c55-fb17-c10708ed43a7" 643 | }, 644 | "outputs": [ 645 | { 646 | "data": { 647 | "text/plain": [ 648 | "785.3999999999999" 649 | ] 650 | }, 651 | "execution_count": 78, 652 | "metadata": {}, 653 | "output_type": "execute_result" 654 | } 655 | ], 656 | "source": [ 657 | "pi = 3.1416\n", 658 | "r = 5\n", 659 | "h = 10\n", 660 | "\n", 661 | "volume_cylinder = pi*r**2*h\n", 662 | "volume_cylinder" 663 | ] 664 | }, 665 | { 666 | "cell_type": "markdown", 667 | "id": "f903fe39-8106-4c39-a3ea-a8d4c70796c0", 668 | "metadata": { 669 | "id": "dc4_32i9arwQ", 670 | "tags": [] 671 | }, 672 | "source": [ 673 | "## **✍️ Example 2: BMI**" 674 | ] 675 | }, 676 | { 677 | "cell_type": "markdown", 678 | "id": "2da4e4d8-9eb5-4d61-919a-cf3eaab02283", 679 | "metadata": { 680 | "id": "2658TWO5ftjq" 681 | }, 682 | "source": [ 683 | "\"string" 684 | ] 685 | }, 686 | { 687 | "cell_type": "code", 688 | "execution_count": 79, 689 | "id": "26766ef3-1e0b-40d7-b86a-152da406995e", 690 | "metadata": {}, 691 | "outputs": [ 692 | { 693 | "data": { 694 | "text/plain": [ 695 | "24.691358024691358" 696 | ] 697 | }, 698 | "execution_count": 79, 699 | "metadata": {}, 700 | "output_type": "execute_result" 701 | } 702 | ], 703 | "source": [ 704 | "weight = 80.\n", 705 | "height = 1.8\n", 706 | "\n", 707 | "bmi = weight / height**2\n", 708 | "bmi" 709 | ] 710 | }, 711 | { 712 | "cell_type": "markdown", 713 | "id": "65641fa2-459f-4de4-a7bb-3746663725e3", 714 | "metadata": { 715 | "id": "dc4_32i9arwQ", 716 | "tags": [] 717 | }, 718 | "source": [ 719 | "## **✍️ Example 3: Gaussian**" 720 | ] 721 | }, 722 | { 723 | "cell_type": "markdown", 724 | "id": "af8e5884-0a00-43b3-8d5e-5d85de267b6d", 725 | "metadata": { 726 | "id": "2658TWO5ftjq" 727 | }, 728 | "source": [ 729 | "\"string" 730 | ] 731 | }, 732 | { 733 | "cell_type": "code", 734 | "execution_count": 87, 735 | "id": "89b56371-787e-4713-8a67-d7001ea6c25b", 736 | "metadata": {}, 737 | "outputs": [ 738 | { 739 | "data": { 740 | "text/plain": [ 741 | "0.054335240837381185" 742 | ] 743 | }, 744 | "execution_count": 87, 745 | "metadata": {}, 746 | "output_type": "execute_result" 747 | } 748 | ], 749 | "source": [ 750 | "m = 0\n", 751 | "x = 2\n", 752 | "s = 1\n", 753 | "exp = 2.71\n", 754 | "pi = 3.14\n", 755 | "\n", 756 | "gaussian = (1/(2*pi*s)**0.5) * exp**(-0.5*((x - m) / s)**2)\n", 757 | "gaussian" 758 | ] 759 | } 760 | ], 761 | "metadata": { 762 | "kernelspec": { 763 | "display_name": "Python 3 (ipykernel)", 764 | "language": "python", 765 | "name": "python3" 766 | }, 767 | "language_info": { 768 | "codemirror_mode": { 769 | "name": "ipython", 770 | "version": 3 771 | }, 772 | "file_extension": ".py", 773 | "mimetype": "text/x-python", 774 | "name": "python", 775 | "nbconvert_exporter": "python", 776 | "pygments_lexer": "ipython3", 777 | "version": "3.9.15" 778 | } 779 | }, 780 | "nbformat": 4, 781 | "nbformat_minor": 5 782 | } 783 | -------------------------------------------------------------------------------- /python/lectures/section-4-comparison.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f18ece75-eec3-40b1-9af8-355087006bb4", 6 | "metadata": { 7 | "id": "PB9MOYPq50Wx", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 4: Comparison and Logical Operators 🐏**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "1bbcdf12-354f-4554-a329-486f4ed4bc68", 17 | "metadata": {}, 18 | "source": [ 19 | "\"string" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "70bb3145-2a25-4fac-8f5b-1141119323a8", 25 | "metadata": { 26 | "id": "A9c3D-3n61Du", 27 | "tags": [] 28 | }, 29 | "source": [ 30 | "## 🔸 **Logical operators**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "id": "ab68c888-a639-4ae5-aeea-d89f8f1e613e", 36 | "metadata": {}, 37 | "source": [ 38 | "\"string" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 49, 44 | "id": "f76d615e-5f24-4c40-adb3-3b7a23c536ec", 45 | "metadata": { 46 | "colab": { 47 | "base_uri": "https://localhost:8080/" 48 | }, 49 | "id": "1NZQwcpJ-ffr", 50 | "outputId": "6a4ac375-079e-4afe-f871-b87906c30913" 51 | }, 52 | "outputs": [], 53 | "source": [ 54 | "a = True\n", 55 | "b = False\n", 56 | "c = True" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 50, 62 | "id": "288a5bea-90c3-424d-8aa0-5b9bbf41f733", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "data": { 67 | "text/plain": [ 68 | "False" 69 | ] 70 | }, 71 | "execution_count": 50, 72 | "metadata": {}, 73 | "output_type": "execute_result" 74 | } 75 | ], 76 | "source": [ 77 | "a and b\n", 78 | "a or b\n", 79 | "a or b and c\n", 80 | "not a" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 51, 86 | "id": "9459903c-5ce3-4b62-a62c-ff022bca0eb6", 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "True" 93 | ] 94 | }, 95 | "execution_count": 51, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "not (a and b)\n", 102 | "not a and b\n", 103 | "not b and a" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "id": "344d32e1-af11-479b-8316-5a174f308763", 109 | "metadata": { 110 | "jp-MarkdownHeadingCollapsed": true, 111 | "tags": [] 112 | }, 113 | "source": [ 114 | "## 🔸 **Comparison operators**" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 55, 120 | "id": "aa688056-d186-4ed2-ae39-f3f9ac6489a8", 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [ 124 | "a = True\n", 125 | "b = False\n", 126 | "\n", 127 | "c = 3.4\n", 128 | "d = 6\n", 129 | "e = 6.\n", 130 | "\n", 131 | "f = 'a'\n", 132 | "g = 'A'\n", 133 | "h = 'a'" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "id": "5661d3ee-ec91-423a-879c-a44bb5a75c6a", 139 | "metadata": {}, 140 | "source": [ 141 | "\"string" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "id": "7b621b52-7a50-4dbb-9099-bf1ebf777bd9", 147 | "metadata": { 148 | "jp-MarkdownHeadingCollapsed": true, 149 | "tags": [] 150 | }, 151 | "source": [ 152 | "### == & !=" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 56, 158 | "id": "6e6881f7-d998-4480-83d2-c3405f1d1db3", 159 | "metadata": { 160 | "colab": { 161 | "base_uri": "https://localhost:8080/" 162 | }, 163 | "id": "p2kobWHG6-rP", 164 | "outputId": "5745ff26-0cac-490d-d319-695cad2ba12e" 165 | }, 166 | "outputs": [ 167 | { 168 | "data": { 169 | "text/plain": [ 170 | "True" 171 | ] 172 | }, 173 | "execution_count": 56, 174 | "metadata": {}, 175 | "output_type": "execute_result" 176 | } 177 | ], 178 | "source": [ 179 | "c == d\n", 180 | "c != d\n", 181 | "d == e" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 60, 187 | "id": "82c97876-00e9-4177-8976-98af26529ed2", 188 | "metadata": { 189 | "colab": { 190 | "base_uri": "https://localhost:8080/" 191 | }, 192 | "id": "zDN5Oe-n80EU", 193 | "outputId": "f276408f-ec05-4614-eb10-e90e1ea3c93e" 194 | }, 195 | "outputs": [ 196 | { 197 | "data": { 198 | "text/plain": [ 199 | "False" 200 | ] 201 | }, 202 | "execution_count": 60, 203 | "metadata": {}, 204 | "output_type": "execute_result" 205 | } 206 | ], 207 | "source": [ 208 | "f == g\n", 209 | "f != g\n", 210 | "\n", 211 | "'salam' == 'Salam'" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "id": "7361e201-d4ba-49f1-abc6-c022c811d117", 217 | "metadata": { 218 | "jp-MarkdownHeadingCollapsed": true, 219 | "tags": [] 220 | }, 221 | "source": [ 222 | "### > & <" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 64, 228 | "id": "ea7b119f-a827-422d-bb2c-86be27f139b6", 229 | "metadata": { 230 | "colab": { 231 | "base_uri": "https://localhost:8080/" 232 | }, 233 | "id": "A14-T6zV9oFK", 234 | "outputId": "811cda0b-e94b-48c5-8cd9-a31963a275cd" 235 | }, 236 | "outputs": [ 237 | { 238 | "data": { 239 | "text/plain": [ 240 | "True" 241 | ] 242 | }, 243 | "execution_count": 64, 244 | "metadata": {}, 245 | "output_type": "execute_result" 246 | } 247 | ], 248 | "source": [ 249 | "c > d\n", 250 | "c < d\n", 251 | "\n", 252 | "d >= e" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 69, 258 | "id": "44ec2db3-8971-4aa5-be9b-2178ca1c0abd", 259 | "metadata": {}, 260 | "outputs": [ 261 | { 262 | "data": { 263 | "text/plain": [ 264 | "True" 265 | ] 266 | }, 267 | "execution_count": 69, 268 | "metadata": {}, 269 | "output_type": "execute_result" 270 | } 271 | ], 272 | "source": [ 273 | "'a' > 'b'\n", 274 | "'a' < 'b'\n", 275 | "'b' < 'z'\n", 276 | "'a' > 'Z'" 277 | ] 278 | }, 279 | { 280 | "cell_type": "markdown", 281 | "id": "dffb314a-4972-4acb-b5ad-3bebaaea68f2", 282 | "metadata": { 283 | "jp-MarkdownHeadingCollapsed": true, 284 | "tags": [] 285 | }, 286 | "source": [ 287 | "### Comparison in list" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": 76, 293 | "id": "3f909d67-f9dd-4f8b-8df4-4d6c34c0a4d9", 294 | "metadata": {}, 295 | "outputs": [ 296 | { 297 | "data": { 298 | "text/plain": [ 299 | "True" 300 | ] 301 | }, 302 | "execution_count": 76, 303 | "metadata": {}, 304 | "output_type": "execute_result" 305 | } 306 | ], 307 | "source": [ 308 | "[1, 3] != [1., 2.]\n", 309 | "[1, 3] > [1, 2, 2]" 310 | ] 311 | }, 312 | { 313 | "cell_type": "markdown", 314 | "id": "7ec0f763-dbb4-4c2a-92ab-e6f5920a75cf", 315 | "metadata": { 316 | "jp-MarkdownHeadingCollapsed": true, 317 | "tags": [] 318 | }, 319 | "source": [ 320 | "### Comparison for floating-point numbers" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 77, 326 | "id": "755da3ec-4760-4e93-bad5-6c788fc7f44f", 327 | "metadata": {}, 328 | "outputs": [ 329 | { 330 | "data": { 331 | "text/plain": [ 332 | "False" 333 | ] 334 | }, 335 | "execution_count": 77, 336 | "metadata": {}, 337 | "output_type": "execute_result" 338 | } 339 | ], 340 | "source": [ 341 | "a = 2.2 + 1.2\n", 342 | "b = 3.4\n", 343 | "a == b" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 78, 349 | "id": "2ef11c0f-8e95-4723-8c74-fd284d4a7214", 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "data": { 354 | "text/plain": [ 355 | "True" 356 | ] 357 | }, 358 | "execution_count": 78, 359 | "metadata": {}, 360 | "output_type": "execute_result" 361 | } 362 | ], 363 | "source": [ 364 | "c = 1.2 + 0.5 \n", 365 | "d = 1.7\n", 366 | "c == d" 367 | ] 368 | }, 369 | { 370 | "cell_type": "code", 371 | "execution_count": 81, 372 | "id": "4d6566aa-df54-4cac-ac01-eeca08e3db4a", 373 | "metadata": {}, 374 | "outputs": [ 375 | { 376 | "data": { 377 | "text/plain": [ 378 | "True" 379 | ] 380 | }, 381 | "execution_count": 81, 382 | "metadata": {}, 383 | "output_type": "execute_result" 384 | } 385 | ], 386 | "source": [ 387 | "abs(a - b) < 1e-5" 388 | ] 389 | }, 390 | { 391 | "cell_type": "code", 392 | "execution_count": 86, 393 | "id": "323ad4df-444c-4232-b5c2-60e7f775ed51", 394 | "metadata": {}, 395 | "outputs": [ 396 | { 397 | "data": { 398 | "text/plain": [ 399 | "0.0022" 400 | ] 401 | }, 402 | "execution_count": 86, 403 | "metadata": {}, 404 | "output_type": "execute_result" 405 | } 406 | ], 407 | "source": [ 408 | "1e-5\n", 409 | "2.2e-3" 410 | ] 411 | }, 412 | { 413 | "cell_type": "markdown", 414 | "id": "fbc88b9d-e47b-4f24-a688-8889ab98952a", 415 | "metadata": { 416 | "tags": [] 417 | }, 418 | "source": [ 419 | "## 🔸 **Combine math, comparison, and logical operators**" 420 | ] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": 91, 425 | "id": "ab7b44a5-b6c8-4ed8-8088-37353263327a", 426 | "metadata": { 427 | "colab": { 428 | "base_uri": "https://localhost:8080/" 429 | }, 430 | "id": "JRQvZp3x_H8S", 431 | "outputId": "2e12f04a-51fc-4d67-b249-8638d9315d6f" 432 | }, 433 | "outputs": [], 434 | "source": [ 435 | "c = 6\n", 436 | "d = 2*3\n", 437 | "e = 'a'\n", 438 | "f = 'a'" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 96, 444 | "id": "86510102-ac6c-4126-86bf-993902d56422", 445 | "metadata": {}, 446 | "outputs": [ 447 | { 448 | "data": { 449 | "text/plain": [ 450 | "False" 451 | ] 452 | }, 453 | "execution_count": 96, 454 | "metadata": {}, 455 | "output_type": "execute_result" 456 | } 457 | ], 458 | "source": [ 459 | "not (c == (2*3) and e == f)\n", 460 | "(c == d) and (e == f)" 461 | ] 462 | }, 463 | { 464 | "cell_type": "markdown", 465 | "id": "babffca6-3a2f-4359-bf4d-298d55913d42", 466 | "metadata": { 467 | "tags": [] 468 | }, 469 | "source": [ 470 | "## 🔸 **Chained comparisons**" 471 | ] 472 | }, 473 | { 474 | "cell_type": "code", 475 | "execution_count": 101, 476 | "id": "fbfe7149-9eef-4492-a453-a54ff1eae169", 477 | "metadata": {}, 478 | "outputs": [ 479 | { 480 | "data": { 481 | "text/plain": [ 482 | "True" 483 | ] 484 | }, 485 | "execution_count": 101, 486 | "metadata": {}, 487 | "output_type": "execute_result" 488 | } 489 | ], 490 | "source": [ 491 | "a = 2.\n", 492 | "b = 5.\n", 493 | "c = 3.\n", 494 | "\n", 495 | "a < c < b\n", 496 | "a < b > c\n", 497 | "a < b < c\n", 498 | "\n", 499 | "1 < 2 < 3 > 1.5 < 2.5 > -0.5\n", 500 | "\n", 501 | "a < c and c < b" 502 | ] 503 | }, 504 | { 505 | "cell_type": "markdown", 506 | "id": "e768ea15-f558-4bca-ae54-7ac94b2b70c7", 507 | "metadata": { 508 | "tags": [] 509 | }, 510 | "source": [ 511 | "## 🔸 **any & all**" 512 | ] 513 | }, 514 | { 515 | "cell_type": "code", 516 | "execution_count": 117, 517 | "id": "4292b0e3-b970-4853-9375-7b2c25bff02f", 518 | "metadata": { 519 | "colab": { 520 | "base_uri": "https://localhost:8080/" 521 | }, 522 | "id": "JRQvZp3x_H8S", 523 | "outputId": "2e12f04a-51fc-4d67-b249-8638d9315d6f" 524 | }, 525 | "outputs": [ 526 | { 527 | "data": { 528 | "text/plain": [ 529 | "(False, True)" 530 | ] 531 | }, 532 | "execution_count": 117, 533 | "metadata": {}, 534 | "output_type": "execute_result" 535 | } 536 | ], 537 | "source": [ 538 | "a = [False, True, False]\n", 539 | "b = [True, True]\n", 540 | "\n", 541 | "any(a), any(b)\n", 542 | "all(a), all(b)" 543 | ] 544 | }, 545 | { 546 | "cell_type": "code", 547 | "execution_count": 120, 548 | "id": "594a287d-8a07-46cf-a7e7-f44040d65cba", 549 | "metadata": {}, 550 | "outputs": [ 551 | { 552 | "data": { 553 | "text/plain": [ 554 | "True" 555 | ] 556 | }, 557 | "execution_count": 121, 558 | "metadata": {}, 559 | "output_type": "execute_result" 560 | } 561 | ], 562 | "source": [ 563 | "a = [0, -1, -2]\n", 564 | "\n", 565 | "any(a)\n", 566 | "all(a)" 567 | ] 568 | }, 569 | { 570 | "cell_type": "markdown", 571 | "id": "aba39402-60ad-4f92-aa11-e4d3b7eca3e9", 572 | "metadata": { 573 | "id": "kr0lLhUw072R", 574 | "tags": [] 575 | }, 576 | "source": [ 577 | "## **✍️ Example 1: Impelement $XOR$**" 578 | ] 579 | }, 580 | { 581 | "cell_type": "markdown", 582 | "id": "d14d2fa2-beed-4f15-b2b3-149ffb935c64", 583 | "metadata": { 584 | "tags": [] 585 | }, 586 | "source": [ 587 | "### $XOR(A,B) = (A \\land \\bar{B}) \\lor (\\bar{A} \\land B)$" 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 142, 593 | "id": "20e27c22-6675-4c60-97b2-b47ae0092069", 594 | "metadata": { 595 | "colab": { 596 | "base_uri": "https://localhost:8080/" 597 | }, 598 | "id": "bExle2w_4XYb", 599 | "outputId": "505cf85f-53bf-4ad5-81e9-c4b439086b9b" 600 | }, 601 | "outputs": [ 602 | { 603 | "data": { 604 | "text/plain": [ 605 | "False" 606 | ] 607 | }, 608 | "execution_count": 142, 609 | "metadata": {}, 610 | "output_type": "execute_result" 611 | } 612 | ], 613 | "source": [ 614 | "a = True\n", 615 | "b = True\n", 616 | "\n", 617 | "xor = (a and not(b)) or (not(a) and b)\n", 618 | "xor" 619 | ] 620 | }, 621 | { 622 | "cell_type": "markdown", 623 | "id": "6a3fcf35-e5a5-4bd0-9674-3cb1c7144444", 624 | "metadata": { 625 | "id": "kr0lLhUw072R", 626 | "tags": [] 627 | }, 628 | "source": [ 629 | "## **✍️ Example 2: Check the data type**" 630 | ] 631 | }, 632 | { 633 | "cell_type": "markdown", 634 | "id": "e185b235-f3e5-4920-9575-dd3396c4161e", 635 | "metadata": {}, 636 | "source": [ 637 | "\"string" 638 | ] 639 | }, 640 | { 641 | "cell_type": "code", 642 | "execution_count": 148, 643 | "id": "960d62f0-8a38-4b51-9e87-2542f781e651", 644 | "metadata": {}, 645 | "outputs": [ 646 | { 647 | "data": { 648 | "text/plain": [ 649 | "False" 650 | ] 651 | }, 652 | "execution_count": 148, 653 | "metadata": {}, 654 | "output_type": "execute_result" 655 | } 656 | ], 657 | "source": [ 658 | "a = 2.5\n", 659 | "\n", 660 | "type(a) == float\n", 661 | "type(a) == int\n", 662 | "type(a) == str\n", 663 | "type(a) == bool" 664 | ] 665 | }, 666 | { 667 | "cell_type": "markdown", 668 | "id": "8dd4be50-af9a-403d-bdc5-2ec2b7ee8593", 669 | "metadata": { 670 | "id": "kr0lLhUw072R", 671 | "tags": [] 672 | }, 673 | "source": [ 674 | "## **✍️ Example 3: Grade of students**" 675 | ] 676 | }, 677 | { 678 | "cell_type": "markdown", 679 | "id": "927fb514-8cc3-47a2-a2c1-5a99abc43ddf", 680 | "metadata": {}, 681 | "source": [ 682 | "\"string\n", 683 | "\"string" 684 | ] 685 | }, 686 | { 687 | "cell_type": "code", 688 | "execution_count": 123, 689 | "id": "3e042163-0541-4144-b03a-027df5d682cd", 690 | "metadata": { 691 | "colab": { 692 | "base_uri": "https://localhost:8080/" 693 | }, 694 | "id": "bExle2w_4XYb", 695 | "outputId": "505cf85f-53bf-4ad5-81e9-c4b439086b9b" 696 | }, 697 | "outputs": [], 698 | "source": [ 699 | "names = [\"Hana\", \"Karter\", \"Landon\", \"Hector\", \"Clarence\", \"Deborah\", \"Scarlett\", \"Joe\", \"Marlene\", \"Lillianna\", \"Santos\", \"Cassius\", \"Darrell\", \"Julie\", \"Kaden\", \"Allyson\", \"Anderson\", \"Sara\", \"John\", \"Brynn\"]\n", 700 | "grades = [68, 83, 61, 70, 75, 82, 57, 5, 76, 85, 62, 71, 96, 78, 76, 68, 72, 75, 83, 93]" 701 | ] 702 | }, 703 | { 704 | "cell_type": "code", 705 | "execution_count": 158, 706 | "id": "65f76be9-721f-45fc-94ac-01aac1a3c843", 707 | "metadata": {}, 708 | "outputs": [ 709 | { 710 | "name": "stdout", 711 | "output_type": "stream", 712 | "text": [ 713 | "John: 83 , Karter: 83 True\n" 714 | ] 715 | } 716 | ], 717 | "source": [ 718 | "name = 'Clarence'\n", 719 | "idx = names.index(name)\n", 720 | "grades[idx]\n", 721 | "\n", 722 | "idx1 = names.index('John')\n", 723 | "idx2 = names.index('Karter')\n", 724 | "grade1 = grades[idx1]\n", 725 | "grade2 = grades[idx2]\n", 726 | "\n", 727 | "print('John:', grade1, ', Karter:', grade2, grade1 == grade2)" 728 | ] 729 | } 730 | ], 731 | "metadata": { 732 | "kernelspec": { 733 | "display_name": "Python 3 (ipykernel)", 734 | "language": "python", 735 | "name": "python3" 736 | }, 737 | "language_info": { 738 | "codemirror_mode": { 739 | "name": "ipython", 740 | "version": 3 741 | }, 742 | "file_extension": ".py", 743 | "mimetype": "text/x-python", 744 | "name": "python", 745 | "nbconvert_exporter": "python", 746 | "pygments_lexer": "ipython3", 747 | "version": "3.9.15" 748 | } 749 | }, 750 | "nbformat": 4, 751 | "nbformat_minor": 5 752 | } 753 | -------------------------------------------------------------------------------- /python/lectures/.ipynb_checkpoints/section-4-comparison-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f18ece75-eec3-40b1-9af8-355087006bb4", 6 | "metadata": { 7 | "id": "PB9MOYPq50Wx", 8 | "tags": [] 9 | }, 10 | "source": [ 11 | "# **Section 4: Comparison and Logical Operators 🐏**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "1bbcdf12-354f-4554-a329-486f4ed4bc68", 17 | "metadata": {}, 18 | "source": [ 19 | "\"string" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "70bb3145-2a25-4fac-8f5b-1141119323a8", 25 | "metadata": { 26 | "id": "A9c3D-3n61Du", 27 | "jp-MarkdownHeadingCollapsed": true, 28 | "tags": [] 29 | }, 30 | "source": [ 31 | "## 🔸 **Logical operators**" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "id": "ab68c888-a639-4ae5-aeea-d89f8f1e613e", 37 | "metadata": {}, 38 | "source": [ 39 | "\"string" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 49, 45 | "id": "f76d615e-5f24-4c40-adb3-3b7a23c536ec", 46 | "metadata": { 47 | "colab": { 48 | "base_uri": "https://localhost:8080/" 49 | }, 50 | "id": "1NZQwcpJ-ffr", 51 | "outputId": "6a4ac375-079e-4afe-f871-b87906c30913" 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "a = True\n", 56 | "b = False\n", 57 | "c = True" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 50, 63 | "id": "288a5bea-90c3-424d-8aa0-5b9bbf41f733", 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "data": { 68 | "text/plain": [ 69 | "False" 70 | ] 71 | }, 72 | "execution_count": 50, 73 | "metadata": {}, 74 | "output_type": "execute_result" 75 | } 76 | ], 77 | "source": [ 78 | "a and b\n", 79 | "a or b\n", 80 | "a or b and c\n", 81 | "not a" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 51, 87 | "id": "9459903c-5ce3-4b62-a62c-ff022bca0eb6", 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "data": { 92 | "text/plain": [ 93 | "True" 94 | ] 95 | }, 96 | "execution_count": 51, 97 | "metadata": {}, 98 | "output_type": "execute_result" 99 | } 100 | ], 101 | "source": [ 102 | "not (a and b)\n", 103 | "not a and b\n", 104 | "not b and a" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "id": "344d32e1-af11-479b-8316-5a174f308763", 110 | "metadata": { 111 | "jp-MarkdownHeadingCollapsed": true, 112 | "tags": [] 113 | }, 114 | "source": [ 115 | "## 🔸 **Comparison operators**" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 55, 121 | "id": "aa688056-d186-4ed2-ae39-f3f9ac6489a8", 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [ 125 | "a = True\n", 126 | "b = False\n", 127 | "\n", 128 | "c = 3.4\n", 129 | "d = 6\n", 130 | "e = 6.\n", 131 | "\n", 132 | "f = 'a'\n", 133 | "g = 'A'\n", 134 | "h = 'a'" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "id": "5661d3ee-ec91-423a-879c-a44bb5a75c6a", 140 | "metadata": {}, 141 | "source": [ 142 | "\"string" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "id": "7b621b52-7a50-4dbb-9099-bf1ebf777bd9", 148 | "metadata": { 149 | "jp-MarkdownHeadingCollapsed": true, 150 | "tags": [] 151 | }, 152 | "source": [ 153 | "### == & !=" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 56, 159 | "id": "6e6881f7-d998-4480-83d2-c3405f1d1db3", 160 | "metadata": { 161 | "colab": { 162 | "base_uri": "https://localhost:8080/" 163 | }, 164 | "id": "p2kobWHG6-rP", 165 | "outputId": "5745ff26-0cac-490d-d319-695cad2ba12e" 166 | }, 167 | "outputs": [ 168 | { 169 | "data": { 170 | "text/plain": [ 171 | "True" 172 | ] 173 | }, 174 | "execution_count": 56, 175 | "metadata": {}, 176 | "output_type": "execute_result" 177 | } 178 | ], 179 | "source": [ 180 | "c == d\n", 181 | "c != d\n", 182 | "d == e" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 60, 188 | "id": "82c97876-00e9-4177-8976-98af26529ed2", 189 | "metadata": { 190 | "colab": { 191 | "base_uri": "https://localhost:8080/" 192 | }, 193 | "id": "zDN5Oe-n80EU", 194 | "outputId": "f276408f-ec05-4614-eb10-e90e1ea3c93e" 195 | }, 196 | "outputs": [ 197 | { 198 | "data": { 199 | "text/plain": [ 200 | "False" 201 | ] 202 | }, 203 | "execution_count": 60, 204 | "metadata": {}, 205 | "output_type": "execute_result" 206 | } 207 | ], 208 | "source": [ 209 | "f == g\n", 210 | "f != g\n", 211 | "\n", 212 | "'salam' == 'Salam'" 213 | ] 214 | }, 215 | { 216 | "cell_type": "markdown", 217 | "id": "7361e201-d4ba-49f1-abc6-c022c811d117", 218 | "metadata": { 219 | "jp-MarkdownHeadingCollapsed": true, 220 | "tags": [] 221 | }, 222 | "source": [ 223 | "### > & <" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 64, 229 | "id": "ea7b119f-a827-422d-bb2c-86be27f139b6", 230 | "metadata": { 231 | "colab": { 232 | "base_uri": "https://localhost:8080/" 233 | }, 234 | "id": "A14-T6zV9oFK", 235 | "outputId": "811cda0b-e94b-48c5-8cd9-a31963a275cd" 236 | }, 237 | "outputs": [ 238 | { 239 | "data": { 240 | "text/plain": [ 241 | "True" 242 | ] 243 | }, 244 | "execution_count": 64, 245 | "metadata": {}, 246 | "output_type": "execute_result" 247 | } 248 | ], 249 | "source": [ 250 | "c > d\n", 251 | "c < d\n", 252 | "\n", 253 | "d >= e" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": 69, 259 | "id": "44ec2db3-8971-4aa5-be9b-2178ca1c0abd", 260 | "metadata": {}, 261 | "outputs": [ 262 | { 263 | "data": { 264 | "text/plain": [ 265 | "True" 266 | ] 267 | }, 268 | "execution_count": 69, 269 | "metadata": {}, 270 | "output_type": "execute_result" 271 | } 272 | ], 273 | "source": [ 274 | "'a' > 'b'\n", 275 | "'a' < 'b'\n", 276 | "'b' < 'z'\n", 277 | "'a' > 'Z'" 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "id": "dffb314a-4972-4acb-b5ad-3bebaaea68f2", 283 | "metadata": { 284 | "jp-MarkdownHeadingCollapsed": true, 285 | "tags": [] 286 | }, 287 | "source": [ 288 | "### Comparison in list" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 76, 294 | "id": "3f909d67-f9dd-4f8b-8df4-4d6c34c0a4d9", 295 | "metadata": {}, 296 | "outputs": [ 297 | { 298 | "data": { 299 | "text/plain": [ 300 | "True" 301 | ] 302 | }, 303 | "execution_count": 76, 304 | "metadata": {}, 305 | "output_type": "execute_result" 306 | } 307 | ], 308 | "source": [ 309 | "[1, 3] != [1., 2.]\n", 310 | "[1, 3] > [1, 2, 2]" 311 | ] 312 | }, 313 | { 314 | "cell_type": "markdown", 315 | "id": "7ec0f763-dbb4-4c2a-92ab-e6f5920a75cf", 316 | "metadata": { 317 | "jp-MarkdownHeadingCollapsed": true, 318 | "tags": [] 319 | }, 320 | "source": [ 321 | "### Comparison for floating-point numbers" 322 | ] 323 | }, 324 | { 325 | "cell_type": "code", 326 | "execution_count": 77, 327 | "id": "755da3ec-4760-4e93-bad5-6c788fc7f44f", 328 | "metadata": {}, 329 | "outputs": [ 330 | { 331 | "data": { 332 | "text/plain": [ 333 | "False" 334 | ] 335 | }, 336 | "execution_count": 77, 337 | "metadata": {}, 338 | "output_type": "execute_result" 339 | } 340 | ], 341 | "source": [ 342 | "a = 2.2 + 1.2\n", 343 | "b = 3.4\n", 344 | "a == b" 345 | ] 346 | }, 347 | { 348 | "cell_type": "code", 349 | "execution_count": 78, 350 | "id": "2ef11c0f-8e95-4723-8c74-fd284d4a7214", 351 | "metadata": {}, 352 | "outputs": [ 353 | { 354 | "data": { 355 | "text/plain": [ 356 | "True" 357 | ] 358 | }, 359 | "execution_count": 78, 360 | "metadata": {}, 361 | "output_type": "execute_result" 362 | } 363 | ], 364 | "source": [ 365 | "c = 1.2 + 0.5 \n", 366 | "d = 1.7\n", 367 | "c == d" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 81, 373 | "id": "4d6566aa-df54-4cac-ac01-eeca08e3db4a", 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/plain": [ 379 | "True" 380 | ] 381 | }, 382 | "execution_count": 81, 383 | "metadata": {}, 384 | "output_type": "execute_result" 385 | } 386 | ], 387 | "source": [ 388 | "abs(a - b) < 1e-5" 389 | ] 390 | }, 391 | { 392 | "cell_type": "code", 393 | "execution_count": 86, 394 | "id": "323ad4df-444c-4232-b5c2-60e7f775ed51", 395 | "metadata": {}, 396 | "outputs": [ 397 | { 398 | "data": { 399 | "text/plain": [ 400 | "0.0022" 401 | ] 402 | }, 403 | "execution_count": 86, 404 | "metadata": {}, 405 | "output_type": "execute_result" 406 | } 407 | ], 408 | "source": [ 409 | "1e-5\n", 410 | "2.2e-3" 411 | ] 412 | }, 413 | { 414 | "cell_type": "markdown", 415 | "id": "fbc88b9d-e47b-4f24-a688-8889ab98952a", 416 | "metadata": { 417 | "jp-MarkdownHeadingCollapsed": true, 418 | "tags": [] 419 | }, 420 | "source": [ 421 | "## 🔸 **Combine math, comparison, and logical operators**" 422 | ] 423 | }, 424 | { 425 | "cell_type": "code", 426 | "execution_count": 91, 427 | "id": "ab7b44a5-b6c8-4ed8-8088-37353263327a", 428 | "metadata": { 429 | "colab": { 430 | "base_uri": "https://localhost:8080/" 431 | }, 432 | "id": "JRQvZp3x_H8S", 433 | "outputId": "2e12f04a-51fc-4d67-b249-8638d9315d6f" 434 | }, 435 | "outputs": [], 436 | "source": [ 437 | "c = 6\n", 438 | "d = 2*3\n", 439 | "e = 'a'\n", 440 | "f = 'a'" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 96, 446 | "id": "86510102-ac6c-4126-86bf-993902d56422", 447 | "metadata": {}, 448 | "outputs": [ 449 | { 450 | "data": { 451 | "text/plain": [ 452 | "False" 453 | ] 454 | }, 455 | "execution_count": 96, 456 | "metadata": {}, 457 | "output_type": "execute_result" 458 | } 459 | ], 460 | "source": [ 461 | "not (c == (2*3) and e == f)\n", 462 | "(c == d) and (e == f)" 463 | ] 464 | }, 465 | { 466 | "cell_type": "markdown", 467 | "id": "babffca6-3a2f-4359-bf4d-298d55913d42", 468 | "metadata": { 469 | "jp-MarkdownHeadingCollapsed": true, 470 | "tags": [] 471 | }, 472 | "source": [ 473 | "## 🔸 **Chained comparisons**" 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 101, 479 | "id": "fbfe7149-9eef-4492-a453-a54ff1eae169", 480 | "metadata": {}, 481 | "outputs": [ 482 | { 483 | "data": { 484 | "text/plain": [ 485 | "True" 486 | ] 487 | }, 488 | "execution_count": 101, 489 | "metadata": {}, 490 | "output_type": "execute_result" 491 | } 492 | ], 493 | "source": [ 494 | "a = 2.\n", 495 | "b = 5.\n", 496 | "c = 3.\n", 497 | "\n", 498 | "a < c < b\n", 499 | "a < b > c\n", 500 | "a < b < c\n", 501 | "\n", 502 | "1 < 2 < 3 > 1.5 < 2.5 > -0.5\n", 503 | "\n", 504 | "a < c and c < b" 505 | ] 506 | }, 507 | { 508 | "cell_type": "markdown", 509 | "id": "e768ea15-f558-4bca-ae54-7ac94b2b70c7", 510 | "metadata": { 511 | "jp-MarkdownHeadingCollapsed": true, 512 | "tags": [] 513 | }, 514 | "source": [ 515 | "## 🔸 **any & all**" 516 | ] 517 | }, 518 | { 519 | "cell_type": "code", 520 | "execution_count": 117, 521 | "id": "4292b0e3-b970-4853-9375-7b2c25bff02f", 522 | "metadata": { 523 | "colab": { 524 | "base_uri": "https://localhost:8080/" 525 | }, 526 | "id": "JRQvZp3x_H8S", 527 | "outputId": "2e12f04a-51fc-4d67-b249-8638d9315d6f" 528 | }, 529 | "outputs": [ 530 | { 531 | "data": { 532 | "text/plain": [ 533 | "(False, True)" 534 | ] 535 | }, 536 | "execution_count": 117, 537 | "metadata": {}, 538 | "output_type": "execute_result" 539 | } 540 | ], 541 | "source": [ 542 | "a = [False, True, False]\n", 543 | "b = [True, True]\n", 544 | "\n", 545 | "any(a), any(b)\n", 546 | "all(a), all(b)" 547 | ] 548 | }, 549 | { 550 | "cell_type": "code", 551 | "execution_count": 120, 552 | "id": "594a287d-8a07-46cf-a7e7-f44040d65cba", 553 | "metadata": {}, 554 | "outputs": [ 555 | { 556 | "data": { 557 | "text/plain": [ 558 | "True" 559 | ] 560 | }, 561 | "execution_count": 121, 562 | "metadata": {}, 563 | "output_type": "execute_result" 564 | } 565 | ], 566 | "source": [ 567 | "a = [0, -1, -2]\n", 568 | "\n", 569 | "any(a)\n", 570 | "all(a)" 571 | ] 572 | }, 573 | { 574 | "cell_type": "markdown", 575 | "id": "aba39402-60ad-4f92-aa11-e4d3b7eca3e9", 576 | "metadata": { 577 | "id": "kr0lLhUw072R", 578 | "jp-MarkdownHeadingCollapsed": true, 579 | "tags": [] 580 | }, 581 | "source": [ 582 | "## **✍️ Example 1: Impelement $XOR$**" 583 | ] 584 | }, 585 | { 586 | "cell_type": "markdown", 587 | "id": "d14d2fa2-beed-4f15-b2b3-149ffb935c64", 588 | "metadata": { 589 | "tags": [] 590 | }, 591 | "source": [ 592 | "### $XOR(A,B) = (A \\land \\bar{B}) \\lor (\\bar{A} \\land B)$" 593 | ] 594 | }, 595 | { 596 | "cell_type": "code", 597 | "execution_count": 142, 598 | "id": "20e27c22-6675-4c60-97b2-b47ae0092069", 599 | "metadata": { 600 | "colab": { 601 | "base_uri": "https://localhost:8080/" 602 | }, 603 | "id": "bExle2w_4XYb", 604 | "outputId": "505cf85f-53bf-4ad5-81e9-c4b439086b9b" 605 | }, 606 | "outputs": [ 607 | { 608 | "data": { 609 | "text/plain": [ 610 | "False" 611 | ] 612 | }, 613 | "execution_count": 142, 614 | "metadata": {}, 615 | "output_type": "execute_result" 616 | } 617 | ], 618 | "source": [ 619 | "a = True\n", 620 | "b = True\n", 621 | "\n", 622 | "xor = (a and not(b)) or (not(a) and b)\n", 623 | "xor" 624 | ] 625 | }, 626 | { 627 | "cell_type": "markdown", 628 | "id": "6a3fcf35-e5a5-4bd0-9674-3cb1c7144444", 629 | "metadata": { 630 | "id": "kr0lLhUw072R", 631 | "jp-MarkdownHeadingCollapsed": true, 632 | "tags": [] 633 | }, 634 | "source": [ 635 | "## **✍️ Example 2: Check the data type**" 636 | ] 637 | }, 638 | { 639 | "cell_type": "markdown", 640 | "id": "e185b235-f3e5-4920-9575-dd3396c4161e", 641 | "metadata": {}, 642 | "source": [ 643 | "\"string" 644 | ] 645 | }, 646 | { 647 | "cell_type": "code", 648 | "execution_count": 148, 649 | "id": "960d62f0-8a38-4b51-9e87-2542f781e651", 650 | "metadata": {}, 651 | "outputs": [ 652 | { 653 | "data": { 654 | "text/plain": [ 655 | "False" 656 | ] 657 | }, 658 | "execution_count": 148, 659 | "metadata": {}, 660 | "output_type": "execute_result" 661 | } 662 | ], 663 | "source": [ 664 | "a = 2.5\n", 665 | "\n", 666 | "type(a) == float\n", 667 | "type(a) == int\n", 668 | "type(a) == str\n", 669 | "type(a) == bool" 670 | ] 671 | }, 672 | { 673 | "cell_type": "markdown", 674 | "id": "8dd4be50-af9a-403d-bdc5-2ec2b7ee8593", 675 | "metadata": { 676 | "id": "kr0lLhUw072R", 677 | "jp-MarkdownHeadingCollapsed": true, 678 | "tags": [] 679 | }, 680 | "source": [ 681 | "## **✍️ Example 3: Grade of students**" 682 | ] 683 | }, 684 | { 685 | "cell_type": "markdown", 686 | "id": "927fb514-8cc3-47a2-a2c1-5a99abc43ddf", 687 | "metadata": {}, 688 | "source": [ 689 | "\"string\n", 690 | "\"string" 691 | ] 692 | }, 693 | { 694 | "cell_type": "code", 695 | "execution_count": 123, 696 | "id": "3e042163-0541-4144-b03a-027df5d682cd", 697 | "metadata": { 698 | "colab": { 699 | "base_uri": "https://localhost:8080/" 700 | }, 701 | "id": "bExle2w_4XYb", 702 | "outputId": "505cf85f-53bf-4ad5-81e9-c4b439086b9b" 703 | }, 704 | "outputs": [], 705 | "source": [ 706 | "names = [\"Hana\", \"Karter\", \"Landon\", \"Hector\", \"Clarence\", \"Deborah\", \"Scarlett\", \"Joe\", \"Marlene\", \"Lillianna\", \"Santos\", \"Cassius\", \"Darrell\", \"Julie\", \"Kaden\", \"Allyson\", \"Anderson\", \"Sara\", \"John\", \"Brynn\"]\n", 707 | "grades = [68, 83, 61, 70, 75, 82, 57, 5, 76, 85, 62, 71, 96, 78, 76, 68, 72, 75, 83, 93]" 708 | ] 709 | }, 710 | { 711 | "cell_type": "code", 712 | "execution_count": 158, 713 | "id": "65f76be9-721f-45fc-94ac-01aac1a3c843", 714 | "metadata": {}, 715 | "outputs": [ 716 | { 717 | "name": "stdout", 718 | "output_type": "stream", 719 | "text": [ 720 | "John: 83 , Karter: 83 True\n" 721 | ] 722 | } 723 | ], 724 | "source": [ 725 | "name = 'Clarence'\n", 726 | "idx = names.index(name)\n", 727 | "grades[idx]\n", 728 | "\n", 729 | "idx1 = names.index('John')\n", 730 | "idx2 = names.index('Karter')\n", 731 | "grade1 = grades[idx1]\n", 732 | "grade2 = grades[idx2]\n", 733 | "\n", 734 | "print('John:', grade1, ', Karter:', grade2, grade1 == grade2)" 735 | ] 736 | } 737 | ], 738 | "metadata": { 739 | "kernelspec": { 740 | "display_name": "Python 3 (ipykernel)", 741 | "language": "python", 742 | "name": "python3" 743 | }, 744 | "language_info": { 745 | "codemirror_mode": { 746 | "name": "ipython", 747 | "version": 3 748 | }, 749 | "file_extension": ".py", 750 | "mimetype": "text/x-python", 751 | "name": "python", 752 | "nbconvert_exporter": "python", 753 | "pygments_lexer": "ipython3", 754 | "version": "3.9.12" 755 | } 756 | }, 757 | "nbformat": 4, 758 | "nbformat_minor": 5 759 | } 760 | --------------------------------------------------------------------------------