\n"
330 | ],
331 | "name": "stdout"
332 | }
333 | ]
334 | },
335 | {
336 | "cell_type": "markdown",
337 | "metadata": {
338 | "id": "AdIWvjezpOHB",
339 | "colab_type": "text"
340 | },
341 | "source": [
342 | "See like I said if you give the input as a string and eval function evaluates the expression and returns the result as an integer.\n",
343 | "\n",
344 | "\n",
345 | "\n",
346 | "---\n",
347 | "\n"
348 | ]
349 | },
350 | {
351 | "cell_type": "markdown",
352 | "metadata": {
353 | "id": "RjQudtaJpPHw",
354 | "colab_type": "text"
355 | },
356 | "source": [
357 | "This is all you need to know to get you started with eval function in python, now you know all the answers for the above questions. The same questions might not be asked all the time, the point is to know the concepts better, then you can answer any questions. If you want to spend some time reading through some material regarding the eval function, I recommend you guys to read the documentation of eval function shown below:\n",
358 | "\n",
359 | "[Python Eval Function](https://docs.python.org/3/library/functions.html?source=post_page-----601f87db191----------------------#eval)\n",
360 | "\n",
361 | "Thank you guys, this is the end of the article like I said this is a small article. If you guys have some doubts or if you are stuck with something, please let me know in the comment sections below, I will definitely answer all your questions. Alright time to say goodbye, have a wonderful day. Also to read my article on Towards Data Science click [here](https://towardsdatascience.com/python-eval-built-in-function-601f87db191).\n",
362 | "\n",
363 | "\n",
364 | "\n",
365 | "---\n",
366 | "\n"
367 | ]
368 | }
369 | ]
370 | }
--------------------------------------------------------------------------------
/Excel_to_PDF_conversion_using_Python_libraries.md:
--------------------------------------------------------------------------------
1 | # Comparision of Excel to PDF Conversion Methods
2 |
3 | ### **Comparison of Excel to PDF Conversion Methods**
4 |
5 | | Features | **`pywin32`** | **`libreoffice`**| **`pdfkit`** |
6 | |:-----------------------------|:----------------------|:----------------------|:----------------|
7 | | **Usability** | ⚠️ Windows-only and requires Excel installed | ✅ Command Line Interface Based | ✅ Easy to Use |
8 | | **Formatting** | ✅ Preserves Excel formatting | ✅ Preserves Excel formatting | ✅ Basic Table|
9 | | **Dependencies** | ⚠️ Requires MS Office (Excel) Installed | ⚠️ Requires `libreOffice` | ✅ Needs `pdfkit` + `wkhtmltopdf` |
10 | | **Performance** | ⚠️ Can be slow for large files | ✅ Very fast | ✅ Fast for small tables |
11 | | **Images/Charts** | ✅ Yes | ✅ Yes | ❌ No |
12 | | **Google Colab Compatibility** | ❌ No (Windows-only) | ✅ Yes | ✅ Yes|
13 | | **Quality** | ✅ High-quality, preserves formatting | ✅ High-quality, preserves formatting | ✅ Good for plain tables |
14 |
--------------------------------------------------------------------------------
/Exercises/Built-InFunctionsPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/Built-InFunctionsPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/Built-InFunctionsProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/Built-InFunctionsProblems.pdf
--------------------------------------------------------------------------------
/Exercises/CommentsAndMathOperatorsPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/CommentsAndMathOperatorsPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/CommentsandMathOperatorsProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/CommentsandMathOperatorsProblems.pdf
--------------------------------------------------------------------------------
/Exercises/FlowControlandComparatorsPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/FlowControlandComparatorsPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/FlowControlandComparatorsProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/FlowControlandComparatorsProblems.pdf
--------------------------------------------------------------------------------
/Exercises/ForLoopsandTuplesPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/ForLoopsandTuplesPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/ForLoopsandTuplesProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/ForLoopsandTuplesProblems.pdf
--------------------------------------------------------------------------------
/Exercises/FunctionsPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/FunctionsPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/FunctionsProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/FunctionsProblems.pdf
--------------------------------------------------------------------------------
/Exercises/IfElseandElifPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/IfElseandElifPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/IfElseandElifProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/IfElseandElifProblems.pdf
--------------------------------------------------------------------------------
/Exercises/ImportingModulesPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/ImportingModulesPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/ImportingModulesProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/ImportingModulesProblems.pdf
--------------------------------------------------------------------------------
/Exercises/ListsPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/ListsPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/ListsProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/ListsProblems.pdf
--------------------------------------------------------------------------------
/Exercises/StringMethodsPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/StringMethodsPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/StringMethodsProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/StringMethodsProblems.pdf
--------------------------------------------------------------------------------
/Exercises/StringsAndEscapeSequencesPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/StringsAndEscapeSequencesPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/StringsAndEscapeSequencesProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/StringsAndEscapeSequencesProblems.pdf
--------------------------------------------------------------------------------
/Exercises/UsingFunctionsWithListsPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/UsingFunctionsWithListsPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/UsingFunctionsWithListsProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/UsingFunctionsWithListsProblems.pdf
--------------------------------------------------------------------------------
/Exercises/VariablesAndDataTypesPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/VariablesAndDataTypesPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exercises/VariablesandDataTypesProblems.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/VariablesandDataTypesProblems.pdf
--------------------------------------------------------------------------------
/Exercises/printPracticeProblemsSolutions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Exercises/printPracticeProblemsSolutions.pdf
--------------------------------------------------------------------------------
/Exploratory Data Analysis/README.md:
--------------------------------------------------------------------------------
1 | # Exploratory Data Analysis in Python.
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Google Translate API/Dataset/Vegetables_names_in_hindi.csv:
--------------------------------------------------------------------------------
1 | Vegetable Names
2 | गाजर
3 | शिमला मिर्च
4 | भिन्डी
5 | मक्का
6 | लाल मिर्च
7 | खीरा
8 | कढ़ी पत्ता
9 | बैगन
10 | लहसुन
11 | अदरक
12 |
--------------------------------------------------------------------------------
/Hacker_Rank_Exercises/Img/hackerrank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Hacker_Rank_Exercises/Img/hackerrank.png
--------------------------------------------------------------------------------
/Hacker_Rank_Exercises/README.md:
--------------------------------------------------------------------------------
1 | # This page deals with solved HackerRank exercises.
2 |
3 |
4 |
5 | HackerRank is a technology company that focuses on competitive programming challenges for both consumers and businesses, where developers compete by trying to program according to provided specifications. HackerRank's programming challenges can be solved in a variety of programming languages (including Java, C++, PHP, Python, SQL, JavaScript) and span multiple computer science domains (Copied from Wikipedia).
6 |
7 | Getting started with HackerRank
8 |
9 | 1. Sign-In/ Sign-Up: (https://www.hackerrank.com/dashboard).
10 |
11 | 2. My Profile at HackerRank: (https://www.hackerrank.com/TanuPrabhu)
12 |
13 | Configuring HackerRank is quite trivial, but solving problems in it is the most the complicated part (The problems are not straightforward, you have to use your brain). Well, I spend some time everyday in it, just to sharpen my programming skills. I hope even you spend quite some time with it. All the best !!!
14 |
--------------------------------------------------------------------------------
/Img/Data.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/Data.PNG
--------------------------------------------------------------------------------
/Img/Jupyter.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/Jupyter.PNG
--------------------------------------------------------------------------------
/Img/Python.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/Python.PNG
--------------------------------------------------------------------------------
/Img/Python.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/Python.jpeg
--------------------------------------------------------------------------------
/Img/Tanu.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/Tanu.jpeg
--------------------------------------------------------------------------------
/Img/gaelle-marcel-vrkSVpOwchk-unsplash.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/gaelle-marcel-vrkSVpOwchk-unsplash.jpg
--------------------------------------------------------------------------------
/Img/hackerrank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/hackerrank.png
--------------------------------------------------------------------------------
/Img/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/logo.jpg
--------------------------------------------------------------------------------
/Img/luke-chesser-JKUTrJ4vK00-unsplash.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/luke-chesser-JKUTrJ4vK00-unsplash.jpg
--------------------------------------------------------------------------------
/Img/sebastian-herrmann-O2o1hzDA7iE-unsplash.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/sebastian-herrmann-O2o1hzDA7iE-unsplash.jpg
--------------------------------------------------------------------------------
/Img/zach-graves-wtpTL_SzmhM-unsplash.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohanmistry231/Python-All-in-One/7c3ee6ee14c5b57f3fac280025e79562d4010746/Img/zach-graves-wtpTL_SzmhM-unsplash.jpg
--------------------------------------------------------------------------------
/Lists/README.md:
--------------------------------------------------------------------------------
1 | # Python Lists.
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Numpy/Numpy_Examples3.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 16,
6 | "metadata": {},
7 | "outputs": [
8 | {
9 | "name": "stdout",
10 | "output_type": "stream",
11 | "text": [
12 | "x = [0 1 2 3]\n",
13 | "x + 5 = [5 6 7 8]\n",
14 | "x - 5 = [-5 -4 -3 -2]\n",
15 | "x * 2 = [0 2 4 6]\n",
16 | "x / 2 = [0. 0.5 1. 1.5]\n",
17 | "x // 2 = [0 0 1 1]\n",
18 | "-x = [ 0 -1 -2 -3]\n",
19 | "x ** 2 = [0 1 4 9]\n",
20 | "x % 2 = [0 1 0 1]\n",
21 | "[2 3 4 5]\n"
22 | ]
23 | }
24 | ],
25 | "source": [
26 | "# Iam very sorry because I had to copy the problems given below directly from the textbook, because it is a redundant process.\n",
27 | "# Moreover the concept of numpy library is a never ending process, because there are a ton of different methods and functions.\n",
28 | "# I think this is more than enough to learn about numpy.\n",
29 | "import numpy as np\n",
30 | "x = np.arange(4)\n",
31 | "print(\"x =\", x)\n",
32 | "print(\"x + 5 =\", x + 5)\n",
33 | "print(\"x - 5 =\", x - 5)\n",
34 | "print(\"x * 2 =\", x * 2)\n",
35 | "print(\"x / 2 =\", x / 2)\n",
36 | "print(\"x // 2 =\", x // 2) # floor division\n",
37 | "print(\"-x = \", -x)\n",
38 | "print(\"x ** 2 = \", x ** 2)\n",
39 | "print(\"x % 2 = \", x % 2)\n",
40 | "print(np.add(x, 2))"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 18,
46 | "metadata": {},
47 | "outputs": [
48 | {
49 | "name": "stdout",
50 | "output_type": "stream",
51 | "text": [
52 | "[2 1 0 1 2]\n",
53 | "---------------------------\n",
54 | "[5. 5. 2. 1.]\n"
55 | ]
56 | }
57 | ],
58 | "source": [
59 | "# Absolute value\n",
60 | "x = np.array([-2, -1, 0, 1, 2])\n",
61 | "print(abs(x))\n",
62 | "print(\"---------------------------\")\n",
63 | "x = np.array([3 - 4j, 4 - 3j, 2 + 0j, 0 + 1j])\n",
64 | "print(np.abs(x))\n"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": 22,
70 | "metadata": {},
71 | "outputs": [
72 | {
73 | "name": "stdout",
74 | "output_type": "stream",
75 | "text": [
76 | "---------------------------\n",
77 | "theta = [0. 1.57079633 3.14159265]\n",
78 | "sin(theta) = [0.0000000e+00 1.0000000e+00 1.2246468e-16]\n",
79 | "cos(theta) = [ 1.000000e+00 6.123234e-17 -1.000000e+00]\n",
80 | "tan(theta) = [ 0.00000000e+00 1.63312394e+16 -1.22464680e-16]\n",
81 | "---------------------------\n",
82 | "x = [-1, 0, 1]\n",
83 | "arcsin(x) = [-1.57079633 0. 1.57079633]\n",
84 | "arccos(x) = [3.14159265 1.57079633 0. ]\n",
85 | "arctan(x) = [-0.78539816 0. 0.78539816]\n"
86 | ]
87 | }
88 | ],
89 | "source": [
90 | "# Trigonometric functions\n",
91 | "\n",
92 | "theta = np.linspace(0, np.pi, 3)\n",
93 | "print(\"---------------------------\")\n",
94 | "print(\"theta = \", theta)\n",
95 | "print(\"sin(theta) = \", np.sin(theta))\n",
96 | "print(\"cos(theta) = \", np.cos(theta))\n",
97 | "print(\"tan(theta) = \", np.tan(theta))\n",
98 | "print(\"---------------------------\")\n",
99 | "\n",
100 | "x = [-1, 0, 1]\n",
101 | "print(\"x = \", x)\n",
102 | "print(\"arcsin(x) = \", np.arcsin(x))\n",
103 | "print(\"arccos(x) = \", np.arccos(x))\n",
104 | "print(\"arctan(x) = \", np.arctan(x))"
105 | ]
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": 25,
110 | "metadata": {},
111 | "outputs": [
112 | {
113 | "name": "stdout",
114 | "output_type": "stream",
115 | "text": [
116 | "x = [1, 2, 3]\n",
117 | "e^x = [ 2.71828183 7.3890561 20.08553692]\n",
118 | "2^x = [2. 4. 8.]\n",
119 | "3^x = [ 3 9 27]\n",
120 | "---------------------------\n",
121 | "x = [1, 2, 4, 10]\n",
122 | "ln(x) = [0. 0.69314718 1.38629436 2.30258509]\n",
123 | "log2(x) = [0. 1. 2. 3.32192809]\n",
124 | "log10(x) = [0. 0.30103 0.60205999 1. ]\n",
125 | "---------------------------\n",
126 | "exp(x) - 1 = [0. 0.0010005 0.01005017 0.10517092]\n",
127 | "log(1 + x) = [0. 0.0009995 0.00995033 0.09531018]\n"
128 | ]
129 | }
130 | ],
131 | "source": [
132 | "# Exponents and logarithms\n",
133 | "x = [1, 2, 3]\n",
134 | "print(\"x =\", x)\n",
135 | "print(\"e^x =\", np.exp(x))\n",
136 | "print(\"2^x =\", np.exp2(x))\n",
137 | "print(\"3^x =\", np.power(3, x))\n",
138 | "print(\"---------------------------\")\n",
139 | "\n",
140 | "x = [1, 2, 4, 10]\n",
141 | "print(\"x =\", x)\n",
142 | "print(\"ln(x) =\", np.log(x))\n",
143 | "print(\"log2(x) =\", np.log2(x))\n",
144 | "print(\"log10(x) =\", np.log10(x))\n",
145 | "print(\"---------------------------\")\n",
146 | "\n",
147 | "x = [0, 0.001, 0.01, 0.1]\n",
148 | "print(\"exp(x) - 1 =\", np.expm1(x))\n",
149 | "print(\"log(1 + x) =\", np.log1p(x))"
150 | ]
151 | },
152 | {
153 | "cell_type": "code",
154 | "execution_count": 29,
155 | "metadata": {},
156 | "outputs": [
157 | {
158 | "name": "stdout",
159 | "output_type": "stream",
160 | "text": [
161 | "gamma(x) = [1.0000e+00 2.4000e+01 3.6288e+05]\n",
162 | "ln|gamma(x)| = [ 0. 3.17805383 12.80182748]\n",
163 | "beta(x, 2) = [0.5 0.03333333 0.00909091]\n",
164 | "---------------------------\n",
165 | "erf(x) = [0. 0.32862676 0.67780119 0.84270079]\n",
166 | "erfc(x) = [1. 0.67137324 0.32219881 0.15729921]\n",
167 | "erfinv(x) = [0. 0.27246271 0.73286908 inf]\n"
168 | ]
169 | }
170 | ],
171 | "source": [
172 | "# Another excellent source for more specialized and obscure ufuncs is the submodule\n",
173 | "# scipy.special. If you want to compute some obscure mathematical function on\n",
174 | "# your data, chances are it is implemented in scipy.special.\n",
175 | "\n",
176 | "from scipy import special\n",
177 | "x = [1, 5, 10]\n",
178 | "print(\"gamma(x) =\", special.gamma(x))\n",
179 | "print(\"ln|gamma(x)| =\", special.gammaln(x))\n",
180 | "print(\"beta(x, 2) =\", special.beta(x, 2))\n",
181 | "print(\"---------------------------\")\n",
182 | "\n",
183 | "# Error function (integral of Gaussian)\n",
184 | "# its complement, and its inverse\n",
185 | "x = np.array([0, 0.3, 0.7, 1.0])\n",
186 | "print(\"erf(x) =\", special.erf(x))\n",
187 | "print(\"erfc(x) =\", special.erfc(x))\n",
188 | "print(\"erfinv(x) =\", special.erfinv(x))\n"
189 | ]
190 | },
191 | {
192 | "cell_type": "code",
193 | "execution_count": 31,
194 | "metadata": {},
195 | "outputs": [
196 | {
197 | "name": "stdout",
198 | "output_type": "stream",
199 | "text": [
200 | "[ 0. 10. 20. 30. 40.]\n",
201 | "---------------------------\n",
202 | "[ 1. 0. 2. 0. 4. 0. 8. 0. 16. 0.]\n"
203 | ]
204 | }
205 | ],
206 | "source": [
207 | "# Advanced Ufunc Features\n",
208 | "# Specifying output\n",
209 | "\n",
210 | "x = np.arange(5)\n",
211 | "y = np.empty(5)\n",
212 | "np.multiply(x, 10, out=y)\n",
213 | "print(y)\n",
214 | "print(\"---------------------------\")\n",
215 | "\n",
216 | "y = np.zeros(10)\n",
217 | "np.power(2, x, out=y[::2])\n",
218 | "print(y)"
219 | ]
220 | },
221 | {
222 | "cell_type": "code",
223 | "execution_count": 35,
224 | "metadata": {},
225 | "outputs": [
226 | {
227 | "name": "stdout",
228 | "output_type": "stream",
229 | "text": [
230 | "15\n",
231 | "---------------------------\n",
232 | "120\n",
233 | "---------------------------\n",
234 | "[ 1 3 6 10 15]\n",
235 | "---------------------------\n",
236 | "[ 1 2 6 24 120]\n"
237 | ]
238 | }
239 | ],
240 | "source": [
241 | "# Aggregates\n",
242 | "x = np.arange(1, 6)\n",
243 | "print(np.add.reduce(x))\n",
244 | "print(\"---------------------------\")\n",
245 | "\n",
246 | "print(np.multiply.reduce(x))\n",
247 | "print(\"---------------------------\")\n",
248 | "\n",
249 | "print(np.add.accumulate(x))\n",
250 | "print(\"---------------------------\")\n",
251 | "\n",
252 | "print(np.multiply.accumulate(x))"
253 | ]
254 | }
255 | ],
256 | "metadata": {
257 | "kernelspec": {
258 | "display_name": "Python 3",
259 | "language": "python",
260 | "name": "python3"
261 | },
262 | "language_info": {
263 | "codemirror_mode": {
264 | "name": "ipython",
265 | "version": 3
266 | },
267 | "file_extension": ".py",
268 | "mimetype": "text/x-python",
269 | "name": "python",
270 | "nbconvert_exporter": "python",
271 | "pygments_lexer": "ipython3",
272 | "version": "3.7.3"
273 | }
274 | },
275 | "nbformat": 4,
276 | "nbformat_minor": 2
277 | }
278 |
--------------------------------------------------------------------------------
/Numpy/Numpy_Examples4.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {},
7 | "outputs": [
8 | {
9 | "name": "stdout",
10 | "output_type": "stream",
11 | "text": [
12 | "[0 1 3 5 7 9]\n"
13 | ]
14 | }
15 | ],
16 | "source": [
17 | "# Sorting Arrays\n",
18 | "# Fast Sorting in NumPy: np.sort and np.argsort\n",
19 | "\n",
20 | "import numpy as np\n",
21 | "\n",
22 | "a = np.array([1, 9, 0, 7, 3, 5])\n",
23 | "sort = np.sort(a)\n",
24 | "print(sort)\n"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": 3,
30 | "metadata": {},
31 | "outputs": [
32 | {
33 | "name": "stdout",
34 | "output_type": "stream",
35 | "text": [
36 | "[2 0 4 5 3 1]\n"
37 | ]
38 | }
39 | ],
40 | "source": [
41 | "# If you want the sorted index then use np.argsort\n",
42 | "\n",
43 | "index = np.argsort(a)\n",
44 | "print(index)"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": 11,
50 | "metadata": {},
51 | "outputs": [
52 | {
53 | "name": "stdout",
54 | "output_type": "stream",
55 | "text": [
56 | "[[7 8 7 3 4 8]\n",
57 | " [6 3 8 8 5 1]\n",
58 | " [3 3 3 2 6 5]\n",
59 | " [5 2 5 6 1 5]]\n",
60 | "-----------------------------------\n",
61 | "[[3 2 3 2 1 1]\n",
62 | " [5 3 5 3 4 5]\n",
63 | " [6 3 7 6 5 5]\n",
64 | " [7 8 8 8 6 8]]\n",
65 | "-----------------------------------\n",
66 | "[[3 4 7 7 8 8]\n",
67 | " [1 3 5 6 8 8]\n",
68 | " [2 3 3 3 5 6]\n",
69 | " [1 2 5 5 5 6]]\n"
70 | ]
71 | }
72 | ],
73 | "source": [
74 | "# Sorting along rows or columns\n",
75 | "\n",
76 | "X = rand.randint(0, 10, (4, 6)) \n",
77 | "print(X)\n",
78 | "print(\"-----------------------------------\")\n",
79 | "# sort each column of X\n",
80 | "a = np.sort(X, axis=0)\n",
81 | "print(a)\n",
82 | "print(\"-----------------------------------\")\n",
83 | "# sort each row of X \n",
84 | "b = np.sort(X, axis =1)\n",
85 | "print(b)"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": 13,
91 | "metadata": {},
92 | "outputs": [
93 | {
94 | "name": "stdout",
95 | "output_type": "stream",
96 | "text": [
97 | "[7 2 3 1 6 5 4]\n",
98 | "------------------------------\n",
99 | "[2 1 3 4 6 5 7]\n"
100 | ]
101 | }
102 | ],
103 | "source": [
104 | "# Partial Sorts: Partitioning\n",
105 | "x = np.array([7, 2, 3, 1, 6, 5, 4]) \n",
106 | "print(x)\n",
107 | "print(\"------------------------------\")\n",
108 | "a = np.partition(x, 3)\n",
109 | "print(a)\n",
110 | "\n",
111 | "# NumPy provides this in the np.partition function. \n",
112 | "# np.partition takes an array and a number K; the result is a new array with the smallest K values to the left of the partition,\n",
113 | "# and the remaining values to the right, in arbitrary order:\n"
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": 14,
119 | "metadata": {},
120 | "outputs": [
121 | {
122 | "name": "stdout",
123 | "output_type": "stream",
124 | "text": [
125 | "[[3 4 7 7 8 8]\n",
126 | " [1 3 5 8 8 6]\n",
127 | " [2 3 3 3 6 5]\n",
128 | " [1 2 5 6 5 5]]\n"
129 | ]
130 | }
131 | ],
132 | "source": [
133 | "b = np.partition(X, 2, axis=1)\n",
134 | "print(b)"
135 | ]
136 | }
137 | ],
138 | "metadata": {
139 | "kernelspec": {
140 | "display_name": "Python 3",
141 | "language": "python",
142 | "name": "python3"
143 | },
144 | "language_info": {
145 | "codemirror_mode": {
146 | "name": "ipython",
147 | "version": 3
148 | },
149 | "file_extension": ".py",
150 | "mimetype": "text/x-python",
151 | "name": "python",
152 | "nbconvert_exporter": "python",
153 | "pygments_lexer": "ipython3",
154 | "version": "3.7.3"
155 | }
156 | },
157 | "nbformat": 4,
158 | "nbformat_minor": 2
159 | }
160 |
--------------------------------------------------------------------------------
/Oil Refineries/Readme.md:
--------------------------------------------------------------------------------
1 | Oil Refineries
2 |
3 |
4 |
5 |
6 |
7 | ## What is a Oil Refinery?
8 |
9 | An oil refinery or petroleum refinery is an industrial process plant where petroleum (crude oil) is transformed and refined into useful products such as gasoline (petrol), diesel fuel, asphalt base, fuel oils, heating oil, kerosene, liquefied petroleum gas and petroleum naphtha. Petrochemicals feedstock like ethylene and propylene can also be produced directly by cracking crude oil without the need of using refined products of crude oil such as naphtha. Source - Wiki
10 |
11 | ---
12 |
13 | ## What do oil refineries do?
14 |
15 | Petroleum refineries convert (refine) crude oil into petroleum products for use as fuels for transportation, heating, paving roads, and generating electricity and as feedstocks for making chemicals. Refining breaks crude oil down into its various components, which are then selectively reconfigured into new products
16 |
17 | ---
18 |
19 | ## How many oil refineries does Canada has?
20 |
21 | Canada is home to 15 refineries, all of which are operated by Canadian Fuels members and represent the country's refining capacity. Canada is a net exporter, mainly to the United States, of refined petroleum products and crude oil
22 |
23 |
24 | ---
25 |
26 | ## List of Canadian Oil Refineries
27 |
28 |
29 |
30 |
31 |
32 | I have gathered the below list of Canadian Oil Refineries by provinces. Thanks to [Oil Sand Magazine](https://www.oilsandsmagazine.com/projects/canadian-refineries) for the data.
33 |
34 | | Name | Province | City | Year | Capacity |
35 | | :---------------- |:---------------- | :---------------- | :---------------- | :---------------- |
36 | | Irving Oil Refinery | New Brunswick | Saint John | 1960 | 300,000 |
37 | | Jean-Gaulin Refinery | Quebec | Lévis | 1971 | 235000 |
38 | | Strathcona Refinery | Alberta | Edmonton | 1974 | 191000 |
39 | | Edmonton Refinery | Alberta | Edmonton | 1951 | 146000 |
40 | | Co-op Refinery | Saskatchewan | Regina | 1935 | 145000 |
41 | | Montreal Refinery | Quebec | Montreal | 1955 | 137000 |
42 | | North Atlantic Refinery | Newfoundland and Labrador | Come By Chance | 1973 | 130000 |
43 | | Sarnia Refinery | Ontario | Sarnia | 1897 | 127000 |
44 | | Scotford Refinery | Alberta | Strathcona County | 1984 | 114000 |
45 | | Nanticoke Refinery | Ontario | Nanticoke | 1978 | 112000 |
46 | | Sarnia Refinery | Ontario | Sarnia | 1953 | 85000 |
47 | | Sturgeon Refinery | Alberta | Sturgeon County | 2020 | 79000 |
48 | | Corunna Refinery | Ontario | Saint Clair | 1952 | 75000 |
49 | | Burnaby Refinery | British Columbia | Burnaby | 1936 | 55000 |
50 | | Lloydminster Refinery | Alberta | Lloydminister | 1947 | 30000 |
51 | | Moose Jaw Refinery | Saskatchewan | Moose Jaw | 1934 | 22000 |
52 | | Clarkson Refinery | Ontario | Mississauga | 1943 | 15600 |
53 | | Prince George Refinery | British Columbia | Prince George | 1967 | 12000 |
54 |
55 | ---
56 |
57 | ## World's largest refineries
58 |
59 |
60 |
61 |
62 |
63 | | Name | State | City | Country | Capacity |
64 | | :---------------- |:---------------- | :---------------- | :---------------- | :---------------- |
65 | | Jamnagar Refinery (Reliance Industries) | Gujarat | Jamnagar | India | 1,240,000 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/Presenting_Python_code_using_RISE.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Presenting Python code using RISE.ipynb",
7 | "provenance": [],
8 | "collapsed_sections": [],
9 | "authorship_tag": "ABX9TyPoW7ZxXRRtBk7u1jwnRQcA",
10 | "include_colab_link": true
11 | },
12 | "kernelspec": {
13 | "name": "python3",
14 | "display_name": "Python 3"
15 | }
16 | },
17 | "cells": [
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "view-in-github",
22 | "colab_type": "text"
23 | },
24 | "source": [
25 | "
"
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {
31 | "id": "O80IfnBGxIQ-"
32 | },
33 | "source": [
34 | "# **Presenting Python code using RISE**\r\n",
35 | "\r\n",
36 | "## **In this article, you will use RISE as a Python jupyter notebook extension for turning it into a live presentation**\r\n",
37 | "\r\n",
38 | "\r\n",
39 | "
\r\n",
40 | "\r\n",
41 | "\r\n",
42 | "\r\n",
43 | "\r\n",
44 | "\r\n"
45 | ]
46 | },
47 | {
48 | "cell_type": "markdown",
49 | "metadata": {
50 | "id": "uXExmJqDy2-M"
51 | },
52 | "source": [
53 | "# **Scenario**\r\n",
54 | "\r\n",
55 | "Your ***boss/professor*** tells you to ***find the largest number in a Python list*** and present the result in front of the whole employees/classmates. Now there are some rules that you need to follow to impress your boss/professor. They should be able to see both the ***documentation and code*** in this presentation. You should ***execute the code*** too. You may use any ***presentation tool*** of your choice. Now, how would you be able to present your code and ace it at the same time?\r\n",
56 | "\r\n",
57 | "---\r\n",
58 | "\r\n",
59 | "\r\n",
60 | "# **Solution**\r\n",
61 | "\r\n",
62 | "\r\n",
63 | "The above scenario can be easily tackled with the help of [RISE](https://rise.readthedocs.io/en/stable/index.html) — a Jupyter Notebook plugin, which can convert your `.ipynb` notebooks into a presentation (slideshow).\r\n",
64 | "\r\n",
65 | "\r\n",
66 | "---"
67 | ]
68 | },
69 | {
70 | "cell_type": "markdown",
71 | "metadata": {
72 | "id": "EvM7k7E_zV_k"
73 | },
74 | "source": [
75 | "# **Steps**\r\n",
76 | "\r\n",
77 | "\r\n",
78 | "## **Below are the six steps to present your python code using RISE**\r\n",
79 | "\r\n",
80 | "\r\n",
81 | "1. Write the python ***code/logic*** for the presentation.\r\n",
82 | "2. Install Python — later the better.\r\n",
83 | "3. Install Jupyter Notebook using the command prompt.\r\n",
84 | "4. Install RISE from the command prompt.\r\n",
85 | "5. After installing, open the Jupyter Notebook and check for the RISE button on the toggle bar.\r\n",
86 | "6. For creating a slide show, click on “***View — Cell Toolbar — Slideshow***”.\r\n",
87 | "\r\n",
88 | "\r\n",
89 | "> Don’t worry, I won’t let you go or leave confused without explaining these steps in a detailed manner. Stay tuned!\r\n",
90 | "\r\n",
91 | "---"
92 | ]
93 | },
94 | {
95 | "cell_type": "markdown",
96 | "metadata": {
97 | "id": "mZ5CIu-8zt_r"
98 | },
99 | "source": [
100 | "# **An explanation for the above steps**\r\n",
101 | "\r\n",
102 | "\r\n",
103 | "## **1. Write the python code/logic for the presentation**\r\n",
104 | "Let’s write the logic of “***find the largest number in a Python list***”. The logic for this will be really minimalistic and easy to understand. Let’s use the below-given algorithm to write the logic:\r\n",
105 | "\r\n",
106 | "* Create a list of values.\r\n",
107 | "* Sort the list using `sort()`.\r\n",
108 | "* Print the last element after it is being sorted."
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "metadata": {
114 | "colab": {
115 | "base_uri": "https://localhost:8080/"
116 | },
117 | "id": "ZqseQY_lz8zj",
118 | "outputId": "49efa8ec-eec7-4697-e6ad-c05057982d15"
119 | },
120 | "source": [
121 | "# Create a list of values\r\n",
122 | "listValues = [-1, 10, -100, -50, 2]\r\n",
123 | "# Sorting the list\r\n",
124 | "listValues.sort()\r\n",
125 | "# Printing the last element\r\n",
126 | "print(\"Largest element in the list is:\", listValues[-1])"
127 | ],
128 | "execution_count": 1,
129 | "outputs": [
130 | {
131 | "output_type": "stream",
132 | "text": [
133 | "Largest element in the list is: 10\n"
134 | ],
135 | "name": "stdout"
136 | }
137 | ]
138 | },
139 | {
140 | "cell_type": "markdown",
141 | "metadata": {
142 | "id": "6-fA6jqE0BCd"
143 | },
144 | "source": [
145 | "When you execute the above code you will be prompted by the largest number in the list.\r\n",
146 | "\r\n",
147 | "---\r\n"
148 | ]
149 | },
150 | {
151 | "cell_type": "markdown",
152 | "metadata": {
153 | "id": "e2WVLwsW0D6n"
154 | },
155 | "source": [
156 | "## **2. Install Python — the later the better**\r\n",
157 | "In this step, you need to download and install Python, but keep in mind the latest version is always the best version. It would be associated with all the additional features and plug-ins, let’s get not very specific here.\r\n",
158 | "\r\n",
159 | "For windows - Download [here](https://www.python.org/downloads/windows/)\r\n",
160 | "\r\n",
161 | "\r\n",
162 | "### **Video Installation**\r\n",
163 | "\r\n",
164 | "Click here for the [video](https://www.youtube.com/embed/UvcQlPZ8ecA)"
165 | ]
166 | },
167 | {
168 | "cell_type": "markdown",
169 | "metadata": {
170 | "id": "IO5uNh5J0_8w"
171 | },
172 | "source": [
173 | "> ***Remember***: There might be a billion of ways to install all the below software, one might use [docker](https://www.docker.com/), [anaconda](https://www.anaconda.com/) or, etc. But I wouldn’t be using any of those. Rather, I would follow the traditional methods which would be easy to understand and ace it. Also, in this tutorial, I would provide the installation commands for windows only, if you want to add any commands for other operating systems, comment section is all yours.\r\n",
174 | "\r\n",
175 | "---\r\n",
176 | "\r\n"
177 | ]
178 | },
179 | {
180 | "cell_type": "markdown",
181 | "metadata": {
182 | "id": "J1osHxJk1L3B"
183 | },
184 | "source": [
185 | "## **3. Install Jupyter Notebook using the command prompt**\r\n",
186 | "\r\n",
187 | "After downloading Python, navigate to the “***Scripts***” folder as shown below:\r\n",
188 | "\r\n",
189 | "\r\n",
190 | "
\r\n",
191 | "\r\n",
192 | "If you don’t know where to find “Scripts” use the below path, you will get it:\r\n",
193 | "\r\n",
194 | "\r\n",
195 | "```\r\n",
196 | "C:\\Users\\*username*\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\r\n",
197 | "```\r\n",
198 | "\r\n",
199 | "\r\n",
200 | "**There are two things that you need to take care of:**\r\n",
201 | "\r\n",
202 | "1. The `username`, in this case, differs. Please double-check this.\r\n",
203 | "2. Sometimes, you won’t be able to find `AppData`, so in this case go to the top and click on `View`, and check the box which says `hidden items`.\r\n",
204 | "\r\n",
205 | "After navigating to the `Scripts` folder. Open the path on your command prompt, or just press Ctrl+A and then type `cmd` and then press Enter, you will be directly navigated to the command prompt from the ***“Scripts”*** path. Use the following command to install Jupyter Notebook from your command prompt.\r\n",
206 | "\r\n",
207 | "```\r\n",
208 | "pip install jupyter notebook\r\n",
209 | "```\r\n",
210 | "\r\n",
211 | "\r\n",
212 | "Wait till it is successfully installed. By the way, the next time you want to open Jupyter Notebook, please type `jupyter notebook` to launch it. After opening the Jupyter Notebook to create a new Python notebook, on the right-hand top corner, click on the drop-down menu and then select Python 3 Notebook.\r\n",
213 | "\r\n",
214 | "### **Video Example**\r\n",
215 | "\r\n",
216 | "Click here for the [video](https://www.youtube.com/embed/otmWEEFysms)"
217 | ]
218 | },
219 | {
220 | "cell_type": "markdown",
221 | "metadata": {
222 | "id": "dozeObJs2vbY"
223 | },
224 | "source": [
225 | "\r\n",
226 | "\r\n",
227 | "---\r\n",
228 | "\r\n"
229 | ]
230 | },
231 | {
232 | "cell_type": "markdown",
233 | "metadata": {
234 | "id": "CPy4c_FX2wA3"
235 | },
236 | "source": [
237 | "## **4. Install RISE from the command prompt**\r\n",
238 | "After you have installed the Jupyter Notebook, the time has now come to install RISE. Just navigate to your command prompt and type in the below command to install it:\r\n",
239 | "\r\n",
240 | "```\r\n",
241 | "pip install RISE\r\n",
242 | "```\r\n",
243 | "\r\n",
244 | "If you need to read furthermore about RISE then there is no better place than the official docs given below:\r\n",
245 | "\r\n",
246 | "[RISE 5.7.1](https://rise.readthedocs.io/en/stable/installation.html)\r\n",
247 | "\r\n",
248 | "---"
249 | ]
250 | },
251 | {
252 | "cell_type": "markdown",
253 | "metadata": {
254 | "id": "3MCyom3a296R"
255 | },
256 | "source": [
257 | "## **5. After installing, open the Jupyter Notebook and check for the RISE button on the toggle bar**\r\n",
258 | "Installing RISE will automatically enable the option on the toggle bar as shown below, which clearly says “***Enter/Exit RISE Slideshow***”. This indicates that you have successfully installed RISE on your device.\r\n",
259 | "\r\n",
260 | "
\r\n",
261 | "\r\n",
262 | "---"
263 | ]
264 | },
265 | {
266 | "cell_type": "markdown",
267 | "metadata": {
268 | "id": "Mlxj-IJm3GqK"
269 | },
270 | "source": [
271 | "## **6. For creating a slide show, click on “View — Cell Toolbar — Slideshow”**\r\n",
272 | "Lastly, when your Python code and the documentation is ready, it’s time to present it. To present it click on the same RISE button it will automatically open your code in a presentation mode, meaning like a slide show as shown below:\r\n",
273 | "\r\n",
274 | "[Slide Show](https://miro.medium.com/max/1050/1*tTseBgtxHLuJSvx6g_cCXw.gif)\r\n",
275 | "\r\n",
276 | "\r\n",
277 | "\r\n",
278 | "\r\n",
279 | "\r\n",
280 | "Now if you need to edit your slides, or change their “***Slide Type***”, you need to navigate to “***View — Cell Toolbar — Slideshow***”. If you want to come out of this mode, select ***“None”*** from the same dropdown.\r\n",
281 | "\r\n",
282 | "
\r\n",
283 | "\r\n",
284 | "\r\n",
285 | "Currently, there are 5 different types of slides as shown below, you can choose from them, go ahead and try it out.\r\n",
286 | "\r\n",
287 | "> ***Note***: You can independently choose a different slide type for every cell. Thanks to RISE.\r\n",
288 | "\r\n",
289 | "
\r\n",
290 | "\r\n",
291 | "\r\n",
292 | "\r\n",
293 | "\r\n",
294 | "### **Video Example**\r\n",
295 | "\r\n",
296 | "Click here for the [video](https://www.youtube.com/embed/utNl9f3gqYQ)\r\n",
297 | "\r\n"
298 | ]
299 | },
300 | {
301 | "cell_type": "markdown",
302 | "metadata": {
303 | "id": "Alzqvxbr3_sX"
304 | },
305 | "source": [
306 | "# **Conclusion**\r\n",
307 | "You have reached the end of this article “***Presenting Python code using RISE***”. I hope you guys have learned a thing or two from this tutorial. Suggestions are always welcomed here. If you have/facing any issues during installations, comment down below. I will respond ASAP. Until then, nail your Python code presentations, show them who is the boss in presentations. Stay tuned for more updates. Have a nice day!\r\n",
308 | "\r\n",
309 | "---"
310 | ]
311 | }
312 | ]
313 | }
--------------------------------------------------------------------------------
/Python Coding Interview Prep/35 Python interview questions for experienced.md:
--------------------------------------------------------------------------------
1 | # Python Coding Interview Questions And Answers - Experienced
2 |
3 | Here Coding compiler sharing a list of 35 Python interview questions for experienced. These Python questions are prepared by expert Python developers. This list of interview questions on Python will help you to crack your next Python job interview. All the best for your future and happy [python learning](https://codingcompiler.com/python-coding-interview-questions-answers/)
4 |
5 | [](https://hits.seeyoufarm.com)
6 |
7 |
8 | ## 1. Debugging a Python Program
9 |
10 | ```python
11 | # By using this command we can debug a python program
12 | python -m pdb python-script.py
13 | ```
14 |
15 | ---
16 |
17 | ## 2. Yield Keyword in Python
18 | ### The keyword in Python can turn any function into a generator. Yields work like a standard return keyword.
19 |
20 | ```python
21 | def days(index):
22 | day = ['S','M','T','W','Tr','F','St']
23 | yield day[index]
24 | yield day[index+1]
25 |
26 | res = days(0)
27 | print(next(res), next(res))
28 |
29 | > S M
30 | ```
31 | ----
32 |
33 | ## 3. Converting a List into a String
34 | ### When we want to convert a list into a string, we can use the `<.join()>` method which joins all the elements into one and returns as a string.
35 |
36 | ```python
37 | days = ['S','M','T','W','Tr','F','St']
38 | ltos = ' '.join(days)
39 | print(ltos)
40 |
41 | > S M T W Tr F St
42 | ```
43 | ---
44 |
45 | ## 4. Converting a List into a Tuple
46 | ### By using Python `` function we can convert a list into a tuple. But we can’t change the list after turning it into tuple, because it becomes immutable.
47 |
48 | ```python
49 | days = ['S','M','T','W','Tr','F','St']
50 | ltos = tuple(days)
51 | print(ltos)
52 |
53 | > ('S', 'M', 'T', 'W', 'Tr', 'F', 'St')
54 | ```
55 | ---
56 |
57 |
58 | ## 5. Converting a List into a Set
59 | ### User can convert list into set by using `` function.
60 |
61 | ```python
62 | days = ['S','M','T','W','Tr','F','St']
63 | ltos = set(days)
64 | print(ltos)
65 |
66 | > {'T', 'W', 'M', 'F', 'S', 'Tr', 'St'}
67 | ```
68 | ---
69 |
70 | ## 6. Counting the occurrences of a particular element in the list
71 | ### We can count the occurrences of an individual element by using a `` function.
72 |
73 | ```python
74 | days = ['S','M','W', 'M','M','F','S']
75 |
76 | print(days.count('M'))
77 |
78 | > 3
79 | ```
80 | ---
81 |
82 | ### 6.1. Counting the occurrences of elements in the list
83 |
84 | ```python
85 | days = ['S','M','M','M','F','S']
86 | y = set(days)
87 |
88 | print([[x,days.count(x)] for x in y])
89 |
90 | > [['M', 3], ['S', 2], ['F', 1]]
91 | ```
92 |
93 | ---
94 |
95 | ## 7. Creating a NumPy Array in Python
96 | ### NumPy arrays are more flexible then lists in Python.
97 |
98 | ```python
99 | import numpy as np
100 |
101 | arr = np.array([1, 2, 3, 4, 5])
102 |
103 | print(arr)
104 | print(type(arr))
105 |
106 | > [1 2 3 4 5]
107 |
108 |
109 | ```
110 | ---
111 |
112 | ## 8. Implement a LRU (Least Recently Used) Cache
113 |
114 | ```python
115 | from collections import OrderedDict
116 |
117 | class LRUCache:
118 | def __init__(self, capacity: int):
119 | self.cache = OrderedDict()
120 | self.capacity = capacity
121 |
122 | def get(self, key: int) -> int:
123 | if key not in self.cache:
124 | return -1
125 | else:
126 | self.cache.move_to_end(key)
127 | return self.cache[key]
128 |
129 | def put(self, key: int, value: int) -> None:
130 | if key in self.cache:
131 | self.cache.move_to_end(key)
132 | self.cache[key] = value
133 | if len(self.cache) > self.capacity:
134 | self.cache.popitem(last=False)
135 |
136 | # Example usage:
137 | lru = LRUCache(2)
138 | lru.put(1, 1)
139 | lru.put(2, 2)
140 | print(lru.get(1))
141 | lru.put(3, 3)
142 |
143 | > 1
144 | ```
145 | ---
146 |
147 | ## 9. Find the Longest Substring Without Repeating Characters
148 |
149 | ```python
150 | def length_of_longest_substring(s: str) -> int:
151 | char_index_map = {}
152 | start = max_length = 0
153 |
154 | for i, char in enumerate(s):
155 | if char in char_index_map and char_index_map[char] >= start:
156 | start = char_index_map[char] + 1
157 | char_index_map[char] = i
158 | max_length = max(max_length, i - start + 1)
159 |
160 | return max_length
161 |
162 | # Example usage:
163 | print(length_of_longest_substring("abcabcbb"))
164 |
165 | > 3
166 |
167 | ```
168 | ---
169 |
170 | ## 10. Find the Kth Largest Element in an Array
171 |
172 | ```python
173 | import heapq
174 |
175 | def find_kth_largest(nums: list, k: int) -> int:
176 | return heapq.nlargest(k, nums)[-1]
177 |
178 | # Example usage:
179 | print(find_kth_largest([3, 2, 1, 5, 6, 4], 2))
180 |
181 | > 5
182 |
183 | ```
184 |
185 | ---
186 |
187 | ## 11. Detect a Cycle in a Linked List
188 |
189 | ```python
190 |
191 | class ListNode:
192 | def __init__(self, value=0, next=None):
193 | self.value = value
194 | self.next = next
195 |
196 | def has_cycle(head: ListNode) -> bool:
197 | slow = fast = head
198 | while fast and fast.next:
199 | slow = slow.next
200 | fast = fast.next.next
201 | if slow == fast:
202 | return True
203 | return False
204 |
205 | # Example usage:
206 | # Creating a linked list with a cycle for demonstration:
207 | node1 = ListNode(1)
208 | node2 = ListNode(2)
209 | node3 = ListNode(3)
210 | node1.next = node2
211 | node2.next = node3
212 | node3.next = node1 # Cycle here
213 | print(has_cycle(node1))
214 |
215 | > True
216 |
217 | ```
218 | ---
219 |
220 | ## 12. Serialize and Deserialize a Binary Tree
221 |
222 | ```python
223 |
224 | class TreeNode:
225 | def __init__(self, val=0, left=None, right=None):
226 | self.val = val
227 | self.left = left
228 | self.right = right
229 |
230 | class Codec:
231 | def serialize(self, root: TreeNode) -> str:
232 | def dfs(node):
233 | if not node:
234 | result.append("None")
235 | else:
236 | result.append(str(node.val))
237 | dfs(node.left)
238 | dfs(node.right)
239 | result = []
240 | dfs(root)
241 | return ','.join(result)
242 |
243 | def deserialize(self, data: str) -> TreeNode:
244 | def dfs():
245 | val = next(values)
246 | if val == "None":
247 | return None
248 | node = TreeNode(int(val))
249 | node.left = dfs()
250 | node.right = dfs()
251 | return node
252 | values = iter(data.split(','))
253 | return dfs()
254 |
255 | # Example usage:
256 | codec = Codec()
257 | tree = TreeNode(1, TreeNode(2), TreeNode(3, TreeNode(4), TreeNode(5)))
258 | serialized = codec.serialize(tree)
259 | print(serialized)
260 | deserialized = codec.deserialize(serialized)
261 |
262 | > "1,2,None,None,3,4,None,None,5,None,None"
263 |
264 | ```
265 | ---
266 |
267 |
268 |
269 |
270 |
271 | [](https://opensource.org/)
272 | [](https://tanu-n-prabhu.github.io/myWebsite.io/)
273 | [](http://commonmark.org)
274 |
275 |
276 |
277 |
278 |
--------------------------------------------------------------------------------
/Python Coding Interview Prep/Basic_calculator.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyMKvR+DF9qlkhkkPrzv+zEK",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "markdown",
31 | "source": [
32 | "# Basic Calculator\n",
33 | "\n",
34 | "## Problem\n",
35 | "\n",
36 | "Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.\n",
37 | "\n",
38 | "> Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().\n",
39 | "\n",
40 | "```\n",
41 | "Example 1\n",
42 | "Input: s = \"1 + 1\"\n",
43 | "Output: 2\n",
44 | "\n",
45 | "Example 2\n",
46 | "Input: s = \"2-1 + 2\"\n",
47 | "Output: 3\n",
48 | "\n",
49 | "Example 3\n",
50 | "Input: s = \"(1+(4+5+2)-3)+(6+8)\"\n",
51 | "Output: 23\n",
52 | "\n",
53 | "Constraints\n",
54 | "1 <= s.length <= 3 * 105\n",
55 | "s consists of digits, '+', '-', '(', ')', and ' '.\n",
56 | "s represents a valid expression.\n",
57 | "'+' is not used as a unary operation (i.e., \"+1\" and \"+(2 + 3)\" is invalid).\n",
58 | "'-' could be used as a unary operation (i.e., \"-1\" and \"-(2 + 3)\" is valid).\n",
59 | "\n",
60 | "There will be no two consecutive operators in the input.\n",
61 | "Every number and running calculation will fit in a signed 32-bit integer.\n"
62 | ],
63 | "metadata": {
64 | "id": "YpjYRBtSkCUr"
65 | }
66 | },
67 | {
68 | "cell_type": "markdown",
69 | "source": [
70 | "## Solution"
71 | ],
72 | "metadata": {
73 | "id": "7P0B3DxAlDNW"
74 | }
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": 1,
79 | "metadata": {
80 | "colab": {
81 | "base_uri": "https://localhost:8080/"
82 | },
83 | "id": "hXwpq4W-jVXC",
84 | "outputId": "5190701d-9b85-49b2-9326-09ca5650df91"
85 | },
86 | "outputs": [
87 | {
88 | "output_type": "stream",
89 | "name": "stdout",
90 | "text": [
91 | "23\n"
92 | ]
93 | }
94 | ],
95 | "source": [
96 | "class Solution:\n",
97 | " def calculate(self, s: str) -> int:\n",
98 | " stack = []\n",
99 | " num = 0\n",
100 | " sign = 1\n",
101 | " result = 0\n",
102 | "\n",
103 | " for char in s:\n",
104 | " if char.isdigit():\n",
105 | " num = num * 10 + int(char)\n",
106 | " elif char == \"+\":\n",
107 | " result += sign * num\n",
108 | " num = 0\n",
109 | " sign = 1\n",
110 | " elif char == \"-\":\n",
111 | " result += sign * num\n",
112 | " num = 0\n",
113 | " sign = -1\n",
114 | " elif char == \"(\":\n",
115 | " stack.append(result)\n",
116 | " stack.append(sign)\n",
117 | " result = 0\n",
118 | " sign = 1\n",
119 | " elif char == \")\":\n",
120 | " result += sign * num\n",
121 | " num = 0\n",
122 | " result *= stack.pop() # Pop the sign.\n",
123 | " result += stack.pop() # Pop the preceding result.\n",
124 | "\n",
125 | " result += sign * num\n",
126 | " return result\n",
127 | "\n",
128 | "\n",
129 | "# Example usage:\n",
130 | "solution = Solution()\n",
131 | "s = \"(1+(4+5+2)-3)+(6+8)\"\n",
132 | "result = solution.calculate(s)\n",
133 | "print(result) # Output: 23"
134 | ]
135 | },
136 | {
137 | "cell_type": "markdown",
138 | "source": [
139 | "## Credits\n",
140 | "\n",
141 | "I would like to thank [Dhirajpatra](https://github.com/dhirajpatra) for writing this piece of code. Feel free to reach him out if you have any questions about Python Programming.\n"
142 | ],
143 | "metadata": {
144 | "id": "xF26di99lOJd"
145 | }
146 | }
147 | ]
148 | }
--------------------------------------------------------------------------------
/Python Coding Interview Prep/Children_with_candy.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyPKS8ATQwYGAld9M5c891zB",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "markdown",
31 | "source": [
32 | "Assigning Candies to Childrens\n",
33 | "\n",
34 | "## Problem Statement\n",
35 | "\n",
36 | "There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.\n",
37 | "You are giving candies to these children subjected to the following requirements:\n",
38 | "Each child must have at least one candy.\n",
39 | "Children with a higher rating get more candies than their neighbors.\n",
40 | "Return the minimum number of candies you need to have to distribute the candies to the children.\n",
41 | "\n",
42 | "## Example\n",
43 | "\n",
44 | "```\n",
45 | "Example 1:**bold text**\n",
46 | "Input: ratings = [1,0,2]\n",
47 | "Output: 5\n",
48 | "Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.\n",
49 | "\n",
50 | "Example 2:\n",
51 | "Input: ratings = [1,2,2]\n",
52 | "Output: 4\n",
53 | "Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.\n",
54 | "The third child gets 1 candy because it satisfies the above two conditions.\n",
55 | "\n",
56 | "Constraints:\n",
57 | "n == ratings.length\n",
58 | "1 <= n <= 2 * 104\n",
59 | "0 <= ratings[i] <= 2 * 104\n",
60 | "```\n",
61 | "\n",
62 | "## Solution"
63 | ],
64 | "metadata": {
65 | "id": "CpCMQv8CXrWL"
66 | }
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": null,
71 | "metadata": {
72 | "colab": {
73 | "base_uri": "https://localhost:8080/"
74 | },
75 | "id": "s26tYMsXWoiD",
76 | "outputId": "d0e766e6-871e-411f-baad-750ba04eab12"
77 | },
78 | "outputs": [
79 | {
80 | "output_type": "stream",
81 | "name": "stdout",
82 | "text": [
83 | "5\n",
84 | "4\n"
85 | ]
86 | }
87 | ],
88 | "source": [
89 | "from typing import List\n",
90 | "\n",
91 | "class Solution:\n",
92 | " def candy(self, ratings: List[int]) -> int:\n",
93 | " n = len(ratings)\n",
94 | " candies = [1] * n\n",
95 | "\n",
96 | " # Iterate from left to right\n",
97 | " for i in range(1, n):\n",
98 | " if ratings[i] > ratings[i - 1]:\n",
99 | " candies[i] = candies[i - 1] + 1\n",
100 | "\n",
101 | " total_candies = candies[n - 1]\n",
102 | "\n",
103 | " # Iterate from right to left and update candies\n",
104 | " for i in range(n - 2, -1, -1):\n",
105 | " if ratings[i] > ratings[i + 1]:\n",
106 | " candies[i] = max(candies[i], candies[i + 1] + 1)\n",
107 | " total_candies += candies[i]\n",
108 | "\n",
109 | " return total_candies\n",
110 | "\n",
111 | "# Example usage\n",
112 | "if __name__ == \"__main__\":\n",
113 | " solution = Solution()\n",
114 | " ratings1 = [1, 0, 2]\n",
115 | " ratings2 = [1, 2, 2]\n",
116 | " print(solution.candy(ratings1)) # Expected output: 5\n",
117 | " print(solution.candy(ratings2)) # Expected output: 4\n"
118 | ]
119 | },
120 | {
121 | "cell_type": "markdown",
122 | "source": [
123 | "## Credits\n",
124 | "\n",
125 | "I would like to thank [Dhirajpatra](https://github.com/dhirajpatra) for writing this piece of code. Feel free to reach him out if you have any questions about Python Programming."
126 | ],
127 | "metadata": {
128 | "id": "3_di5W04imv6"
129 | }
130 | }
131 | ]
132 | }
--------------------------------------------------------------------------------
/Python Coding Interview Prep/Python_Interview_Questions_and_Answers.md:
--------------------------------------------------------------------------------
1 | # Mastering Python Interviews: Essential Questions and Expert Answers
2 | ## Your Ultimate Guide to Acing Python Coding Interviews with Confidence
3 |
4 |
5 | |  |
6 | |:--:|
7 | | Photo by Zach Graves on Unsplash|
8 |
9 |
10 | [](https://hits.seeyoufarm.com)
11 |
12 | ## Introduction
13 | In the ever-evolving world of software development, Python has emerged as one of the most popular programming languages, thanks to its simplicity, versatility, and extensive community support. Whether you're a seasoned developer or a beginner, Python’s readable syntax and robust libraries make it a preferred choice for tasks ranging from web development to data science and machine learning.
14 |
15 | As the demand for Python developers continues to grow, so does the competition in landing a role in this field. Preparing for Python coding interviews requires not only a strong grasp of fundamental concepts but also the ability to solve problems efficiently. This article aims to equip you with a comprehensive set of Python interview questions and answers, covering everything from basic syntax to advanced topics. Whether you're gearing up for your first coding interview or looking to refine your skills, this guide will help you navigate the key concepts and strategies to succeed in your next Python interview.
16 |
17 | This introduction sets the stage by highlighting Python’s importance and the value of preparing for coding interviews, appealing to both newcomers and experienced developers.
18 |
19 | ---
20 |
21 | ## 1. Discuss some characteristics of the Python programming language.
22 |
23 | Python is object-oriented, it's easy to read and makes complex tasks simple. It's a Rapid Application Development (RAD) program, and I often use it as a scripting language. It's an interpreted language, dynamically typed, and its functions are first-class objects. You can use any text editor to write Python. Python uses third-party modules, is compatible with all major operating systems, and dynamically uses variables. Other reasons it's popular are its outstanding library, it's ability to support big data, and that it can expedite test-driven development.
24 |
25 | ---
26 |
27 | ## 2. What are some of Python's core default modules?
28 |
29 | Default modules include email, which is parsed and generated by Python. Other default modules are XML support, string, and databases.
30 |
31 | ---
32 |
33 | ## 3. Discuss the frameworks for app development that are popular with Python users.
34 |
35 | Python is an excellent general-purpose dynamic language because it's easy to understand and implement. It's popular for creating various apps for mobile phones because of its interactive environment. It runs on the major operating systems, and there are many frameworks for using Python. For instance, Pyramid, Circuits, and CherryPy as well as other frameworks are Flask, Web2Py, Pycnic, and Django.
36 |
37 | ---
38 |
39 | ## 4. How does Python manage memory?
40 |
41 | Python manages memory with private heap space. The private heap holds Python objects and data structures. The memory manager assigns objects. The garbage collector recycles any unused memory and routes it to the heap space.
42 |
43 | ---
44 |
45 | ## 5. Explain and give an example of inheritance
46 |
47 | The inheritance function gives one class the characteristics and methods of another class. The child class, or the derived class, gains the characteristics. Super-class is the data sending the characteristics. The reason for inheritance is to create and maintain apps and deliver code reusability. Python supports three types of inheritance. One is the single inheritance where a derived class obtains a single superclass. The second Python inheritance is multi-faceted where data can inherit a derived class from another. Finally, multiple inheritance means that a child class receives all the methods and attributes from one or more base, or parent, classes.
48 |
49 | ---
50 |
51 | ## 6. What are arrays in Python?
52 |
53 | An array is a special variable that holds more than one value at a time. Python doesn't have built-in arrays, so instead, we can use lists. Alternatively, to develop arrays in Python I might import a library like NumPy. Arrays contain mixed data types, and the numarray module even provides support for IDL-style array operations, multi-dimensional arrays, and the 'where' function. The numarray only works with numbers, and its length is the highest array index plus one. Lists support objects and strings but can also convert to arrays.
54 |
55 | ---
56 |
57 | ## 7. What are Python’s key features?
58 |
59 | * **Interpreted** - Python code is executed line-by-line.
60 | * **Dynamically Typed** - No need to declare the data type of variables.
61 | Garbage Collection: Automatic memory management.
62 | Extensive Libraries: Large standard library and third-party modules.
63 | Object-Oriented: Supports OOP with classes and objects.
64 | Cross-Platform: Runs on various platforms without modification.
65 | 2. Explain Python’s memory management.
66 | Python uses a private heap to store objects and data structures.
67 | Memory management includes reference counting for garbage collection.
68 | The gc (garbage collector) module can be used to manually manage memory.
69 | 3. What are Python’s data types?
70 | Numeric Types: int, float, complex
71 | Sequence Types: list, tuple, range
72 | Text Type: str
73 | Set Types: set, frozenset
74 | Mapping Type: dict
75 | Boolean Type: bool
76 | None Type: NoneType
77 | 4. How is memory managed in Python?
78 | Memory management is handled by the Python memory manager.
79 | It includes private heap space and garbage collection.
80 | Python’s memory manager automatically handles the allocation and deallocation of memory.
81 | 5. What is the difference between deep copy and shallow copy?
82 | Shallow Copy: Creates a new object but inserts references to the same objects in the original.
83 | python
84 | Copy code
85 | import copy
86 | original_list = [[1, 2], [3, 4]]
87 | shallow_copy = copy.copy(original_list)
88 | Deep Copy: Creates a new object and recursively copies all objects found in the original.
89 | python
90 | Copy code
91 | deep_copy = copy.deepcopy(original_list)
92 | 6. What are Python decorators?
93 | Decorators are functions that modify the behavior of another function or method.
94 | They are commonly used for logging, enforcing access control, instrumentation, etc.
95 | python
96 | Copy code
97 | def decorator(func):
98 | def wrapper():
99 | print("Something before the function.")
100 | func()
101 | print("Something after the function.")
102 | return wrapper
103 |
104 | @decorator
105 | def say_hello():
106 | print("Hello!")
107 | 7. What are Python’s built-in data structures?
108 | List: Ordered, mutable, allows duplicates.
109 | Tuple: Ordered, immutable, allows duplicates.
110 | Set: Unordered, mutable, no duplicates.
111 | Dictionary: Key-value pairs, unordered, mutable.
112 | 8. Explain the use of Python’s with statement.
113 | The with statement simplifies exception handling by encapsulating standard uses of try/finally statements in so-called context managers.
114 | Example with file handling:
115 | python
116 | Copy code
117 | with open('file.txt', 'r') as file:
118 | data = file.read()
119 | 9. How does Python handle exceptions?
120 | Python uses try, except, finally, and else blocks to handle exceptions.
121 | python
122 | Copy code
123 | try:
124 | result = 10 / 0
125 | except ZeroDivisionError:
126 | print("Cannot divide by zero!")
127 | finally:
128 | print("Execution complete.")
129 | 10. What are Python’s lambda functions?
130 | Anonymous functions defined using the lambda keyword.
131 | python
132 | Copy code
133 | add = lambda x, y: x + y
134 | print(add(2, 3)) # Output: 5
135 | 11. Explain list comprehension.
136 | A concise way to create lists using a single line of code.
137 | python
138 | Copy code
139 | squares = [x**2 for x in range(10)]
140 | 12. What are Python’s *args and **kwargs?
141 | *args is used to pass a variable number of positional arguments.
142 | **kwargs is used to pass a variable number of keyword arguments.
143 | python
144 | Copy code
145 | def example_function(*args, **kwargs):
146 | print(args)
147 | print(kwargs)
148 | example_function(1, 2, 3, name="John", age=30)
149 | 13. What is Python’s GIL (Global Interpreter Lock)?
150 | The GIL is a mutex that protects access to Python objects, preventing multiple native threads from executing Python bytecodes simultaneously in CPython.
151 | It simplifies memory management but can be a bottleneck in CPU-bound multi-threaded programs.
152 | 14. How is Python different from other programming languages?
153 | Python emphasizes readability and simplicity.
154 | It is dynamically typed and interpreted.
155 | It has extensive libraries and is often considered more beginner-friendly.
156 | 15. What is the difference between Python 2 and Python 3?
157 | Print Statement: Python 2 uses print, Python 3 uses print().
158 | Integer Division: Python 2’s division of integers truncates the decimal, Python 3 returns a float.
159 | Unicode: Python 3 uses Unicode by default for strings.
160 | These questions cover fundamental concepts and common practices in Python, providing a solid foundation for coding interviews.
161 |
162 |
--------------------------------------------------------------------------------
/Python Coding Interview Prep/Python_Interview_Questions_and_Answers_Strings.md:
--------------------------------------------------------------------------------
1 | # Python Interview Questions and Answers - Strings 2025
2 | ## Master Advanced String Manipulation Techniques for Python Interviews
3 |
4 | | |
5 | |:--:|
6 | | Photo by Gaelle Marcel on Unsplash |
7 |
8 |
9 |
10 | [](https://hits.seeyoufarm.com)
11 |
12 | # Introduction
13 |
14 | Strings are a fundamental aspect of Python programming, playing a crucial role in many applications, from web development to data analysis. In technical interviews, string manipulation questions are commonly asked to evaluate a candidate’s problem-solving abilities and understanding of key programming concepts.
15 |
16 | This repository focuses on advanced Python string interview questions and their solutions. It covers a wide range of topics, including permutations, palindromes, anagram grouping, regular expression matching, and more. Whether you're preparing for a coding interview or looking to enhance your Python skills, these examples will provide valuable insights and practical techniques to handle complex string problems efficiently.
17 |
18 | Dive into these advanced string challenges and sharpen your skills to ace your next technical interview!
19 |
20 | ---
21 |
22 | ## 1. Python program to remove characters from a string
23 |
24 |
25 | Hint
26 |
27 |
28 | > **Input** - Python
29 | >
30 | > **Input Character** - o
31 | >
32 | > **Output** - Pythn
33 |
34 |
35 |
36 |
37 | ```python
38 | str = "Python"
39 | ch = "o"
40 | print(str.replace(ch," "))
41 |
42 | >> Pyth n
43 |
44 | ```
45 |
46 | ---
47 |
48 | ## 2. Python Program to count occurrence of characters in string
49 |
50 | Hint
51 |
52 |
53 | > **Input** - Python
54 | >
55 | > **Input Character** - o
56 | >
57 | > **Output** - 1
58 |
59 |
60 |
61 |
62 | ```python
63 | string = "Python"
64 | char = "y"
65 | count = 0
66 | for i in range(len(string)):
67 | if(string[i] == char):
68 | count = count + 1
69 | print(count)
70 |
71 | >> 1
72 |
73 | ```
74 | ---
75 |
76 | ## 3. Python program in to check string is anagrams or not
77 |
78 | Hint
79 |
80 |
81 | > Input - Python
82 | >
83 | > Input Character - onypth
84 | >
85 | > Output - Anagrams
86 |
87 |
88 |
89 |
90 | ```python
91 | str1 = "python"
92 | str2 = "yonthp"
93 | if (sorted(str1) == sorted(str2)):
94 | print("Anagram")
95 | else:
96 | print("Not an anagram")
97 |
98 | > Anagram
99 |
100 | ```
101 |
102 | ---
103 |
104 | ## 4. Python program to check string is palindrome or not
105 |
106 | Hint
107 |
108 |
109 | > Input - madam
110 | >
111 | > Output - Palindrome
112 |
113 |
114 |
115 |
116 | ```python
117 | string = "madam"
118 | if(string == string[:: - 1]):
119 | print("Palindrome")
120 | else:
121 | print("Not a Palindrome")
122 |
123 | > Palindrome
124 |
125 | ```
126 | ---
127 |
128 | ## 5. Python code to check given character is digit or not
129 |
130 | Hint
131 |
132 |
133 | > Input - a
134 | >
135 | > Output - Not a Digit
136 |
137 |
138 |
139 |
140 | ```python
141 | ch = 'a'
142 | if ch >= '0' and ch <= '9':
143 | print("Digit")
144 | else:
145 | print("Not a Digit")
146 |
147 | > Not a Digit
148 |
149 |
150 | ```
151 | ---
152 |
153 | ## 6. Program to replace the string space with any given character
154 |
155 | Hint
156 |
157 |
158 | > Input - m m
159 | >
160 | > Input charcter - a
161 | >
162 | > Output - mam
163 |
164 |
165 |
166 |
167 | ```python
168 | string = "m d m"
169 | result = ''
170 | ch = "a"
171 | for i in string:
172 | if i == ' ':
173 | i = ch
174 | result += i
175 | print(result)
176 |
177 | > madam
178 |
179 | ```
180 |
181 | ---
182 |
183 | ## 7. Check if Two Strings are Permutations of Each Other
184 |
185 | ```python
186 | def are_permutations(s1: str, s2: str) -> bool:
187 | if len(s1) != len(s2):
188 | return False
189 | return sorted(s1) == sorted(s2)
190 |
191 | # Example usage:
192 | print(are_permutations("abc", "cab"))
193 |
194 | > True
195 |
196 | ```
197 |
198 | ---
199 |
200 | ## 8. Find All Permutations of a Given String
201 |
202 | ```python
203 | from itertools import permutations
204 |
205 | def string_permutations(s: str) -> list:
206 | return [''.join(p) for p in permutations(s)]
207 |
208 | # Example usage:
209 | print(string_permutations("ABC"))
210 |
211 | > ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
212 |
213 | ```
214 | ---
215 |
216 | ## 9. Find the Longest Palindromic Substring
217 |
218 | ```python
219 | def longest_palindromic_substring(s: str) -> str:
220 | def expand_around_center(left: int, right: int) -> str:
221 | while left >= 0 and right < len(s) and s[left] == s[right]:
222 | left -= 1
223 | right += 1
224 | return s[left+1:right]
225 |
226 | longest = ""
227 | for i in range(len(s)):
228 | # Odd length palindrome
229 | substr1 = expand_around_center(i, i)
230 | # Even length palindrome
231 | substr2 = expand_around_center(i, i + 1)
232 | longest = max(longest, substr1, substr2, key=len)
233 | return longest
234 |
235 | # Example usage:
236 | print(longest_palindromic_substring("babad"))
237 |
238 | > "bab" or "aba"
239 |
240 | ```
241 | ---
242 |
243 | ## 10. Count and Group Anagrams from a List of Strings
244 |
245 | ```python
246 |
247 | from collections import defaultdict
248 |
249 | def group_anagrams(words: list) -> dict:
250 | anagrams = defaultdict(list)
251 | for word in words:
252 | sorted_word = ''.join(sorted(word))
253 | anagrams[sorted_word].append(word)
254 | return dict(anagrams)
255 |
256 | # Example usage:
257 | print(group_anagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))
258 |
259 | > {'aet': ['eat', 'tea', 'ate'], 'ant': ['tan', 'nat'], 'abt': ['bat']}
260 |
261 | ```
262 | ---
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 | [](https://opensource.org/)
273 | [](https://tanu-n-prabhu.github.io/myWebsite.io/)
274 | [](http://commonmark.org)
275 |
276 |
277 |
--------------------------------------------------------------------------------
/Python Coding Interview Prep/README.md:
--------------------------------------------------------------------------------
1 | # Python Coding Interview Preparation 2024
2 | ## Last Minute Python Review
3 | |  |
4 | |:--:|
5 | | Image Credits [Omada Search](https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.omadasearch.com%2F2020%2F03%2F7-interview-questions-to-help-determine-the-best-candidate%2F&psig=AOvVaw3IMwK6o41H_A9XbVmeV72D&ust=1649477361590000&source=images&cd=vfe&ved=0CAsQjhxqFwoTCIDshZfMg_cCFQAAAAAdAAAAABAX) |
6 |
7 | [](https://hits.seeyoufarm.com)
8 |
9 | ### Table of Contents
10 |
11 | 1. [35 Python interview questions for experienced](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/35%20Python%20interview%20questions%20for%20experienced.md)
12 |
13 | 2. [Python Coding Interview Questions (Beginner to Advanced)](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Python%20Coding%20Interview%20Questions%20(Beginner%20to%20Advanced).md)
14 |
15 | 3. [Python Interview Questions - Strings](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Python_Interview_Questions_and_Answers_Strings.md)
16 |
17 | 4. [Python Theoretical Interview Questions](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Python_Theoritical_Interview_Questions.md)
18 |
19 |
20 | 5. [Python Interview Questions and Answers 2025 ](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Python_Interview_Questions_and_Answers.md)
21 |
22 | 6. [Assigning Candies to Children Problem with Solution](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Children_with_candy.ipynb)
23 |
24 | 7. [Basic Calculator](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Basic_calculator.ipynb)
25 |
26 | 8. [Text Justification](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Text_Justification.ipynb)
27 |
28 | 9. [Removing an Element](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Remove_Element.ipynb)
29 |
30 | 10. [Vowel Count in a Sentence](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Vowel_Count.ipynb)
31 |
32 | 11. [Pick-Up Line Generator - Based on Sentiments](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/pick_up_line_generator_sentiments.ipynb)
33 |
34 | 12. [Sentimental Analysis](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Sentimental_Analysis.ipynb)
35 |
36 | 13. [Creating a Regular Polygon Visualizer Using Matplotlib in Python](https://github.com/Tanu-N-Prabhu/Python/blob/master/Python%20Coding%20Interview%20Prep/Draw_polygon.ipynb)
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | > Note - This page is dynamic, new content and snippets will be added every hour/day. Stay Tuned!
47 |
--------------------------------------------------------------------------------
/Python Coding Interview Prep/Remove_Element.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyOYQMaKnPTttORNM3cYKBx4",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "markdown",
31 | "source": [
32 | "# Removing an Element\n",
33 | "\n",
34 | "## Problem\n",
35 | "\n",
36 | "Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.\n",
37 | "\n",
38 | "Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:\n",
39 | "\n",
40 | "Change the array nums such that the first k elements of nums contain the elements which are not equal to val. The remaining elements of nums are not important as well as the size of nums.\n",
41 | "Return k.\n",
42 | "\n",
43 | "```\n",
44 | "Custom Judge:\n",
45 | "\n",
46 | "The judge will test your solution with the following code:\n",
47 | "int[] nums = [...]; // Input array\n",
48 | "int val = ...; // Value to remove\n",
49 | "int[] expectedNums = [...]; // The expected answer with correct length.\n",
50 | " // It is sorted with no values equaling val.\n",
51 | "int k = removeElement(nums, val); // Calls your implementation\n",
52 | "assert k == expectedNums.length;\n",
53 | "sort(nums, 0, k); // Sort the first k elements of nums\n",
54 | "for (int i = 0; i < actualLength; i++) {\n",
55 | " assert nums[i] == expectedNums[i];\n",
56 | "}\n",
57 | "\n",
58 | "If all assertions pass, then your solution will be accepted.\n",
59 | "Example 1:\n",
60 | "Input: nums = [3,2,2,3], val = 3\n",
61 | "Output: 2, nums = [2,2,_,_]\n",
62 | "Explanation: Your function should return k = 2, with the first two elements of nums being 2.\n",
63 | "It does not matter what you leave beyond the returned k (hence they are underscores).\n",
64 | "Example 2:\n",
65 | "Input: nums = [0,1,2,2,3,0,4,2], val = 2\n",
66 | "Output: 5, nums = [0,1,4,0,3,_,_,_]\n",
67 | "Explanation: Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4.\n",
68 | "Note that the five elements can be returned in any order.\n",
69 | "It does not matter what you leave beyond the returned k (hence they are underscores).\n",
70 | "Constraints:\n",
71 | "0 <= nums.length <= 100\n",
72 | "0 <= nums[i] <= 50\n",
73 | "0 <= val <= 100\n",
74 | "\n",
75 | "```\n",
76 | "\n",
77 | "## Solution\n"
78 | ],
79 | "metadata": {
80 | "id": "VXIFNA8N5w_r"
81 | }
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": 4,
86 | "metadata": {
87 | "colab": {
88 | "base_uri": "https://localhost:8080/"
89 | },
90 | "id": "OGhBr5xF5l6h",
91 | "outputId": "9807ea09-e7d8-4f34-b32c-2eb5b3cb7e4f"
92 | },
93 | "outputs": [
94 | {
95 | "output_type": "stream",
96 | "name": "stdout",
97 | "text": [
98 | "2\n",
99 | "[2, 2]\n",
100 | "5\n",
101 | "[0, 1, 3, 0, 4]\n"
102 | ]
103 | }
104 | ],
105 | "source": [
106 | "from typing import List\n",
107 | "\n",
108 | "class Solution:\n",
109 | " def removeElement(self, nums: List[int], val: int) -> int:\n",
110 | " # Initialize two pointers, one for iterating the list and one for the insertion point.\n",
111 | " i = 0\n",
112 | " k = 0\n",
113 | "\n",
114 | " while i < len(nums):\n",
115 | " if nums[i] != val:\n",
116 | " # If the current element is not equal to val, copy it to the insertion point.\n",
117 | " nums[k] = nums[i]\n",
118 | " k += 1\n",
119 | " i += 1\n",
120 | "\n",
121 | " return k\n",
122 | "\n",
123 | "# Example usage and custom judge test\n",
124 | "if __name__ == \"__main__\":\n",
125 | " solution = Solution()\n",
126 | "\n",
127 | " # Test case 1\n",
128 | " nums1 = [3, 2, 2, 3]\n",
129 | " val1 = 3\n",
130 | " k1 = solution.removeElement(nums1, val1)\n",
131 | " print(k1) # Expected output: 2\n",
132 | " print(nums1[:k1]) # Expected output: [2, 2]\n",
133 | "\n",
134 | " # Test case 2\n",
135 | " nums2 = [0, 1, 2, 2, 3, 0, 4, 2]\n",
136 | " val2 = 2\n",
137 | " k2 = solution.removeElement(nums2, val2)\n",
138 | " print(k2) # Expected output: 5\n",
139 | " print(nums2[:k2]) # Expected output: [0, 1, 4, 0, 3]"
140 | ]
141 | }
142 | ]
143 | }
--------------------------------------------------------------------------------
/Python Coding Interview Prep/Sentimental_Analysis.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyMjUJE1hCPosygYRij3Dr+a",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "markdown",
31 | "source": [
32 | "# Problem Statement: Sentiment Analysis\n",
33 | "\n",
34 | "Develop a Python program that analyzes the sentiment of a given text input. Sentiment analysis involves determining whether a piece of text expresses positive, negative, or neutral sentiments. The program should utilize the TextBlob library, which provides a simple API for sentiment analysis.\n",
35 | "\n",
36 | "## Requirements:\n",
37 | "\n",
38 | "1. The program should prompt the user to input a text for sentiment analysis.\n",
39 | "2. It should analyze the sentiment of the input text using TextBlob.\n",
40 | "3. The sentiment analysis should include determining the polarity and subjectivity of the text.\n",
41 | "4. The program should categorize the sentiment as positive, negative, or neutral based on the polarity.\n",
42 | "5. It should display the sentiment category (positive, negative, or neutral), the polarity value (ranging from -1 to 1), and the subjectivity value (ranging from 0 to 1).\n",
43 | "\n",
44 | "\n",
45 | "```\n",
46 | "Enter text to analyze sentiment: I love this movie, it's fantastic!\n",
47 | "Sentiment: Positive\n",
48 | "Polarity: 0.8\n",
49 | "Subjectivity: 0.9\n",
50 | "```\n",
51 | "\n",
52 | "> **Note**: Ensure error handling is implemented to handle unexpected inputs or errors during sentiment analysis."
53 | ],
54 | "metadata": {
55 | "id": "mEjFkntDjnWu"
56 | }
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": 3,
61 | "metadata": {
62 | "colab": {
63 | "base_uri": "https://localhost:8080/"
64 | },
65 | "id": "-qpc20bSjTRV",
66 | "outputId": "1ca4fb88-2bbd-4437-fb8d-7d98f8372b9c"
67 | },
68 | "outputs": [
69 | {
70 | "output_type": "stream",
71 | "name": "stdout",
72 | "text": [
73 | "Enter text to analyze sentiment: Happy\n",
74 | "Sentiment: Positive\n",
75 | "Polarity: 0.8\n",
76 | "Subjectivity: 1.0\n"
77 | ]
78 | }
79 | ],
80 | "source": [
81 | "from textblob import TextBlob\n",
82 | "\n",
83 | "def analyze_sentiment(text):\n",
84 | " analysis = TextBlob(text)\n",
85 | "\n",
86 | " # Get polarity and subjectivity\n",
87 | " polarity = analysis.sentiment.polarity\n",
88 | " subjectivity = analysis.sentiment.subjectivity\n",
89 | "\n",
90 | " # Determine sentiment\n",
91 | " if polarity > 0:\n",
92 | " sentiment = \"Positive\"\n",
93 | " elif polarity < 0:\n",
94 | " sentiment = \"Negative\"\n",
95 | " else:\n",
96 | " sentiment = \"Neutral\"\n",
97 | "\n",
98 | " return sentiment, polarity, subjectivity\n",
99 | "\n",
100 | "text = input(\"Enter text to analyze sentiment: \")\n",
101 | "sentiment, polarity, subjectivity = analyze_sentiment(text)\n",
102 | "print(f\"Sentiment: {sentiment}\")\n",
103 | "print(f\"Polarity: {polarity}\")\n",
104 | "print(f\"Subjectivity: {subjectivity}\")\n"
105 | ]
106 | }
107 | ]
108 | }
--------------------------------------------------------------------------------
/Python Coding Interview Prep/Text_Justification.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyN4KVKP11K8h3IJFKwyJG/H",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "markdown",
31 | "source": [
32 | "# Text Justification\n",
33 | "\n",
34 | "## Problem\n",
35 | "\n",
36 | "Given an array of strings words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.\n",
37 | "\n",
38 | "You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.\n",
39 | "Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.\n",
40 | "For the last line of text, it should be left-justified, and no extra space is inserted between words.\n",
41 | "\n",
42 | "> **Note**: A word is defined as a character sequence consisting of non-space characters only.\n",
43 | "Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.\n",
44 | "The input array words contains at least one word.\n",
45 | "\n",
46 | "```\n",
47 | "\n",
48 | "Example 1:\n",
49 | "Input: words = [\"This\", \"is\", \"an\", \"example\", \"of\", \"text\", \"justification.\"], maxWidth = 16\n",
50 | "Output:\n",
51 | "[\n",
52 | " \"This is an\",\n",
53 | " \"example of text\",\n",
54 | " \"justification. \"\n",
55 | "]\n",
56 | "\n",
57 | "Example 2:\n",
58 | "Input: words = [\"What\",\"must\",\"be\",\"acknowledgment\",\"shall\",\"be\"], maxWidth = 16\n",
59 | "Output:\n",
60 | "[\n",
61 | " \"What must be\",\n",
62 | " \"acknowledgment \",\n",
63 | " \"shall be \"\n",
64 | "]\n",
65 | "\n",
66 | "Explanation: Note that the last line is \"shall be \" instead of \"shall be\", because the last line must be left-justified instead of fully-justified.\n",
67 | "Note that the second line is also left-justified because it contains only one word.\n",
68 | "\n",
69 | "Example 3:\n",
70 | "Input: words = [\"Science\",\"is\",\"what\",\"we\",\"understand\",\"well\",\"enough\",\"to\",\"explain\",\"to\",\"a\",\"computer.\",\"Art\",\"is\",\"everything\",\"else\",\"we\",\"do\"], maxWidth = 20\n",
71 | "Output:\n",
72 | "[\n",
73 | " \"Science is what we\",\n",
74 | " \"understand well\",\n",
75 | " \"enough to explain to\",\n",
76 | " \"a computer. Art is\",\n",
77 | " \"everything else we\",\n",
78 | " \"do \"\n",
79 | "]\n",
80 | "\n",
81 | "Constraints:\n",
82 | "1 <= words.length <= 300\n",
83 | "1 <= words[i].length <= 20\n",
84 | "words[i] consists of only English letters and symbols.\n",
85 | "1 <= maxWidth <= 100\n",
86 | "words[i].length <= maxWidth\n",
87 | "\n",
88 | "```\n",
89 | "\n",
90 | "## Solution"
91 | ],
92 | "metadata": {
93 | "id": "5r-EUJ-HPl06"
94 | }
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": 3,
99 | "metadata": {
100 | "colab": {
101 | "base_uri": "https://localhost:8080/"
102 | },
103 | "id": "aWMvEJ7kPgiJ",
104 | "outputId": "aa7bd169-8371-4ce6-f6e0-7e2a9d8dd88d"
105 | },
106 | "outputs": [
107 | {
108 | "output_type": "stream",
109 | "name": "stdout",
110 | "text": [
111 | "This is an\n",
112 | "example of text\n",
113 | "justification. \n",
114 | "What must be\n",
115 | "acknowledgment \n",
116 | "shall be \n",
117 | "Science is what\n",
118 | "we understand\n",
119 | "well enough to\n",
120 | "explain to a\n",
121 | "computer. Art is\n",
122 | "everything else\n",
123 | "we do \n"
124 | ]
125 | }
126 | ],
127 | "source": [
128 | "class Solution:\n",
129 | " def fullJustify(self, words, maxWidth):\n",
130 | " result = []\n",
131 | " line, line_length = [], 0\n",
132 | "\n",
133 | " for word in words:\n",
134 | " if line_length + len(word) + len(line) <= maxWidth:\n",
135 | " line.append(word)\n",
136 | " line_length += len(word)\n",
137 | " else:\n",
138 | " spaces_needed = maxWidth - line_length\n",
139 | " if len(line) == 1:\n",
140 | " result.append(line[0] + ' ' * spaces_needed)\n",
141 | " else:\n",
142 | " space_between_words, extra_spaces = divmod(spaces_needed, len(line) - 1)\n",
143 | " line_str = ''\n",
144 | " for i in range(len(line) - 1):\n",
145 | " line_str += line[i] + ' ' * (space_between_words + (1 if i < extra_spaces else 0))\n",
146 | " line_str += line[-1]\n",
147 | " result.append(line_str)\n",
148 | "\n",
149 | " line, line_length = [word], len(word)\n",
150 | "\n",
151 | " result.append(' '.join(line).ljust(maxWidth))\n",
152 | " return result\n",
153 | "\n",
154 | "\n",
155 | "# Example usage\n",
156 | "if __name__ == \"__main__\":\n",
157 | " solution = Solution()\n",
158 | " words1 = [\"This\", \"is\", \"an\", \"example\", \"of\", \"text\", \"justification.\"]\n",
159 | " words2 = [\"What\", \"must\", \"be\", \"acknowledgment\", \"shall\", \"be\"]\n",
160 | " words3 = [\"Science\", \"is\", \"what\", \"we\", \"understand\", \"well\", \"enough\", \"to\", \"explain\", \"to\", \"a\", \"computer.\",\n",
161 | " \"Art\", \"is\", \"everything\", \"else\", \"we\", \"do\"]\n",
162 | "\n",
163 | " maxWidth = 16\n",
164 | "\n",
165 | " result1 = solution.fullJustify(words1, maxWidth)\n",
166 | " result2 = solution.fullJustify(words2, maxWidth)\n",
167 | " result3 = solution.fullJustify(words3, maxWidth)\n",
168 | "\n",
169 | " for line in result1:\n",
170 | " print(line)\n",
171 | "\n",
172 | " for line in result2:\n",
173 | " print(line)\n",
174 | "\n",
175 | " for line in result3:\n",
176 | " print(line)"
177 | ]
178 | },
179 | {
180 | "cell_type": "markdown",
181 | "source": [
182 | "## Credits\n",
183 | "\n",
184 | "I would like to thank [Dhirajpatra](https://github.com/dhirajpatra) for writing this piece of code. Feel free to reach him out if you have any questions about Python Programming."
185 | ],
186 | "metadata": {
187 | "id": "rMlLUZrKRRyz"
188 | }
189 | }
190 | ]
191 | }
--------------------------------------------------------------------------------
/Python Coding Interview Prep/Vowel_Count.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyOqQvMYSVHffQwcSDCIXmsN",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "markdown",
31 | "source": [
32 | "# Counting Vowels in a Sentence\n",
33 | "\n",
34 | "\n",
35 | "## Problem\n",
36 | "\n",
37 | "You are tasked with creating a Python script that counts the number of vowels in a given sentence. Your program should prompt the user to enter a sentence, and then output the total count of vowels present in that sentence. The program should treat both uppercase and lowercase vowels as equivalent.\n",
38 | "\n",
39 | "Your task is to write a Python script that accomplishes this, utilizing functions and loops as necessary."
40 | ],
41 | "metadata": {
42 | "id": "oQbsz2YwDc_f"
43 | }
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": 1,
48 | "metadata": {
49 | "colab": {
50 | "base_uri": "https://localhost:8080/"
51 | },
52 | "id": "XAU5DlE0DZpU",
53 | "outputId": "43f94197-a8b0-42c5-fb3b-248340f81b1d"
54 | },
55 | "outputs": [
56 | {
57 | "output_type": "stream",
58 | "name": "stdout",
59 | "text": [
60 | "Enter a sentence: Hello I am a Sales Expert\n",
61 | "Number of vowels: 9\n"
62 | ]
63 | }
64 | ],
65 | "source": [
66 | "def count_vowels(sentence):\n",
67 | " vowels = 'aeiouAEIOU'\n",
68 | " vowel_count = 0\n",
69 | " for char in sentence:\n",
70 | " if char in vowels:\n",
71 | " vowel_count += 1\n",
72 | " return vowel_count\n",
73 | "\n",
74 | "sentence = input(\"Enter a sentence: \")\n",
75 | "print(\"Number of vowels:\", count_vowels(sentence))\n"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "source": [
81 | "This script defines a function count_vowels that takes a sentence as input and returns the count of vowels in it. It iterates over each character in the sentence and checks if it is a vowel. If it is, it increments the count. Finally, it prints out the total count of vowels in the sentence.\n",
82 | "\n",
83 | "\n"
84 | ],
85 | "metadata": {
86 | "id": "euH9m_htD6tG"
87 | }
88 | }
89 | ]
90 | }
--------------------------------------------------------------------------------
/Python Coding Interview Prep/pick_up_line_generator_sentiments.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyOXEOuU+2MwSdeSjS6kYtev",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "markdown",
31 | "source": [
32 | "# Pick-up Line Generator - Sentimental Analysis\n",
33 | "\n",
34 | "## Problem Statement\n",
35 | "\n",
36 | "You are tasked with creating a Python script for a pick-up line generator. The program should generate pick-up lines based on different sentiments such as romantic, funny, cheesy, or flirty.\n",
37 | "\n",
38 | "### Requirements:\n",
39 | "\n",
40 | "The script should contain a function generate_pickup_line(sentiment) that takes a sentiment as input and returns a randomly selected pick-up line from the corresponding sentiment category.\n",
41 | "The sentiment categories and pick-up lines should be organized in a dictionary or a similar data structure within the script.\n",
42 | "The program should allow users to specify the sentiment category for the pick-up line they want to generate.\n",
43 | "The script should include a main section where it prompts the user to enter a sentiment category, calls the generate_pickup_line function with the specified sentiment, and prints the generated pick-up line.\n",
44 | "\n",
45 | "\n",
46 | "```\n",
47 | "Enter the sentiment category for the pick-up line (romantic/funny/cheesy/flirty): flirty\n",
48 | "Generated pick-up line: Are you a magician? Because whenever I look at you, everyone else disappears.\n",
49 | "```\n"
50 | ],
51 | "metadata": {
52 | "id": "viG6NBRUzlpg"
53 | }
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": 2,
58 | "metadata": {
59 | "colab": {
60 | "base_uri": "https://localhost:8080/"
61 | },
62 | "id": "gAJgWyq9zfyQ",
63 | "outputId": "ed1fb610-1301-40f0-f1b8-d2f498012afc"
64 | },
65 | "outputs": [
66 | {
67 | "output_type": "stream",
68 | "name": "stdout",
69 | "text": [
70 | "You are the reason for my smile.\n"
71 | ]
72 | }
73 | ],
74 | "source": [
75 | "import random\n",
76 | "\n",
77 | "def generate_pickup_line(sentiment):\n",
78 | " # Dictionary of pick-up lines categorized by sentiment\n",
79 | " pickup_lines = {\n",
80 | " \"romantic\": [\n",
81 | " \"You are the reason for my smile.\",\n",
82 | " \"I never believed in love at first sight until I saw you.\",\n",
83 | " \"You must be a shooting star because you light up my life.\",\n",
84 | " \"I want to be the reason you look down at your phone and smile.\"\n",
85 | " ],\n",
86 | " \"funny\": [\n",
87 | " \"Do you have a name, or can I call you mine?\",\n",
88 | " \"Are you made of copper and tellurium? Because you're Cu-Te.\",\n",
89 | " \"If you were a vegetable, you'd be a cute-cumber.\",\n",
90 | " \"Do you have a sunburn, or are you always this hot?\"\n",
91 | " ],\n",
92 | " \"cheesy\": [\n",
93 | " \"Do you have a map? I keep getting lost in your eyes.\",\n",
94 | " \"Is your name Google? Because you have everything I've been searching for.\",\n",
95 | " \"Are you a bank loan? Because you have my interest.\",\n",
96 | " \"Do you believe in love at first sight, or should I walk by again?\"\n",
97 | " ],\n",
98 | " \"flirty\": [\n",
99 | " \"Are you a magician? Because whenever I look at you, everyone else disappears.\",\n",
100 | " \"Do you have a Band-Aid? Because I just scraped my knee falling for you.\",\n",
101 | " \"Are you a camera? Because every time I look at you, I smile.\",\n",
102 | " \"If beauty were a crime, you'd be serving a life sentence.\"\n",
103 | " ]\n",
104 | " }\n",
105 | "\n",
106 | " # Select a pick-up line based on the specified sentiment\n",
107 | " return random.choice(pickup_lines[sentiment])\n",
108 | "\n",
109 | "if __name__ == \"__main__\":\n",
110 | " # Specify the sentiment category\n",
111 | " sentiment = \"romantic\" # Change this to \"romantic\", \"funny\", or \"cheesy\" as desired\n",
112 | " print(generate_pickup_line(sentiment))\n"
113 | ]
114 | }
115 | ]
116 | }
--------------------------------------------------------------------------------
/Python Coding Interview Questions And Answers Fixed.py:
--------------------------------------------------------------------------------
1 | import numpy as np # Import NumPy for efficient arrays (habit for numerical tasks)
2 |
3 | def debug_script(filename): # Reusable debugging function with clear naming
4 | """Starts the Python debugger for the given script."""
5 | import pdb # Import pdb for debugging
6 | pdb.runfile(filename) # Concise way to start debugging
7 |
8 | def days_generator(start_index=0): # Generator function for day names
9 | """Yields day names sequentially, starting from the given index."""
10 | days = ['S', 'M', 'T', 'W', 'Tr', 'F', 'St']
11 | for day in days[start_index:]:
12 | yield day
13 |
14 | def list_to_string(data): # Function to handle various data types
15 | """Converts a list, tuple, or set to a string with spaces between elements."""
16 | if isinstance(data, (list, tuple, set)):
17 | return ' '.join(data)
18 | raise TypeError("Input must be a list, tuple, or set") # Handle invalid input
19 |
20 | def count_occurrences(data, element): # Function for counting occurrences
21 | """Counts the number of times 'element' appears in 'data' (list or tuple)."""
22 | if not isinstance(data, (list, tuple)):
23 | raise TypeError("Input must be a list or tuple")
24 | return data.count(element)
25 |
26 | def create_numpy_array(data): # Function for array creation (flexible for different data types)
27 | """Creates a NumPy array from a list, tuple, or even another NumPy array."""
28 | return np.array(data)
29 |
30 | # Example usage (can be refactored into a more modular structure if needed)
31 | day_gen = days_generator(2) # Get day names starting from index 2 (Wednesday)
32 | print(next(day_gen)) # Print the first day
33 |
34 | weekdays = ['M', 'W', 'F']
35 | print(list_to_string(weekdays)) # Print weekdays as a string
36 |
37 | my_list = [1, 2, 2, 3, 4]
38 | print(count_occurrences(my_list, 2)) # Count occurrences of 2
39 |
40 | data = [5, 6, 7]
41 | arr = create_numpy_array(data)
42 | print(arr.dtype) # Check the array's data type (habit for type awareness)
43 |
--------------------------------------------------------------------------------
/Python_Variables.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Python Variables.ipynb",
7 | "provenance": [],
8 | "authorship_tag": "ABX9TyNaHyzT8vEu+M5zbjDt87/W",
9 | "include_colab_link": true
10 | },
11 | "kernelspec": {
12 | "name": "python3",
13 | "display_name": "Python 3"
14 | }
15 | },
16 | "cells": [
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "id": "view-in-github",
21 | "colab_type": "text"
22 | },
23 | "source": [
24 | "
"
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {
30 | "id": "yRgHPumxce8E",
31 | "colab_type": "text"
32 | },
33 | "source": [
34 | "# **Python Variables**\n",
35 | "\n",
36 | "\n",
37 | "\n",
38 | "\n",
39 | "In programming languages like C/C++, every time a variable is declared simultaneously a memory would be allocated this would allocation would completely depend on the variable type. Therefore, the programmers must specify the variable type while creating a variable. But luckily in Python, you don’t have to do that. Python doesn’t have a variable type declaration. Like pointers in C, variables in Python don’t store values legitimately; they work with references highlighting objects in memory.\n",
40 | "\n",
41 | "## **Variables**\n",
42 | "\n",
43 | "A variable is more likely a ***container*** to store the values. Now the values to be stored depends on the programmer whether to use integer, float, string or **[etc](https://www.w3schools.com/python/python_datatypes.asp)**.\n",
44 | "\n",
45 | "\n",
46 | "\n",
47 | "> ***A Variable is like a box in the computer’s memory where you can store a single value. — Al Sweigart***\n",
48 | "\n",
49 | "\n",
50 | "Unlike in other programming languages, in Python, you need not declare any variables or initialize them. Please read [this](https://stackoverflow.com/a/11008311/11646278).\n",
51 | "\n",
52 | "\n",
53 | "### **Syntax**\n",
54 | "\n",
55 | "\n",
56 | "The general syntax to create a variable in Python is as shown below:\n",
57 | "\n",
58 | "`variable_name = value`\n",
59 | "\n",
60 | "The `variable_name` in Python can be short as sweet as `a, b, x, y, ...` or can be very informative such as `age, height, name, student_name, covid, ...`\n",
61 | "\n",
62 | "\n",
63 | "> ***Although it is recommended keeping a very descriptive variable name to improve the readability.***\n",
64 | "\n",
65 | "\n",
66 | "\n",
67 | "### **Rules**\n",
68 | "\n",
69 | "**All set and done, there are some rules that you need to follow while naming a variable:**\n",
70 | "\n",
71 | "* A variable name must start with a ***letter*** or the ***underscore character***\n",
72 | "\n",
73 | "* A variable name cannot start with a ***number***\n",
74 | "\n",
75 | "* A variable name can only contain ***alpha-numeric characters*** and ***underscores***. For example, anything like this is valid: ***A-z, 0–9, and _***\n",
76 | "\n",
77 | "* Variable names are ***case-sensitive*** ***(height, Height***, and ***HEIGHT*** are three different variables names)\n",
78 | "\n",
79 | "### **Example**\n",
80 | "\n",
81 | "Below given is an example to properly initialize a value to a variable:"
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "metadata": {
87 | "id": "NQKdREzkdw76",
88 | "colab_type": "code",
89 | "colab": {
90 | "base_uri": "https://localhost:8080/",
91 | "height": 35
92 | },
93 | "outputId": "70b43a3d-c3b4-4846-f786-64b07890bb4d"
94 | },
95 | "source": [
96 | "# This is a valid and good way to assign a value to a variable\n",
97 | "# For example you might want to assign values to variables to calculate the area of a circle\n",
98 | "\n",
99 | "pi = 3.142 # I could have also used \"math\" library (math.pi)\n",
100 | "radius = 5 # Interger value for radius\n",
101 | "area_of_circle = 0 # Used to store the value of area of circle\n",
102 | "\n",
103 | "area_of_circle = pi * (radius) ** 2 # Area = (PI * R^2)\n",
104 | "\n",
105 | "print(\"The area of the circle based on the given data is: \", area_of_circle)"
106 | ],
107 | "execution_count": 1,
108 | "outputs": [
109 | {
110 | "output_type": "stream",
111 | "text": [
112 | "The area of the circle based on the given data is: 78.55\n"
113 | ],
114 | "name": "stdout"
115 | }
116 | ]
117 | },
118 | {
119 | "cell_type": "markdown",
120 | "metadata": {
121 | "id": "DIyEuUw8d3aU",
122 | "colab_type": "text"
123 | },
124 | "source": [
125 | "### **Pictorial Example (Skim it quickly)**\n",
126 | "I# believe just by seeing a picture or an image, the concepts can be understood more quickly. Below is the pictorial representation of a variable and it being stored in the memory.\n",
127 | "\n",
128 | "\n",
129 | "\n",
130 | "\n",
131 | "\n",
132 | "\n",
133 | "\n",
134 | "\n",
135 | "\n",
136 | "---"
137 | ]
138 | }
139 | ]
140 | }
--------------------------------------------------------------------------------
/Quiz/Python_Quiz_2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Python-Quiz-2.ipynb",
7 | "provenance": [],
8 | "collapsed_sections": [],
9 | "authorship_tag": "ABX9TyNii4wqrlRrcrdwe1t9wlTX",
10 | "include_colab_link": true
11 | },
12 | "kernelspec": {
13 | "name": "python3",
14 | "display_name": "Python 3"
15 | }
16 | },
17 | "cells": [
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "view-in-github",
22 | "colab_type": "text"
23 | },
24 | "source": [
25 | "
"
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {
31 | "id": "m19wGHCDy4cI"
32 | },
33 | "source": [
34 | "# **Python Basics - Quiz-2**\n",
35 | "\n",
36 | "## **Use this to enhance to your python skill**"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {
42 | "id": "NrLPKFeYy7H8"
43 | },
44 | "source": [
45 | "### **1) What is the output of the below code**\n",
46 | "1. p\n",
47 | "2. r\n",
48 | "3. o\n",
49 | "4. None of the above"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "metadata": {
55 | "id": "YbwWPoh1yTM9"
56 | },
57 | "source": [
58 | "'''\n",
59 | "Program: 1\n",
60 | "Description: Finding the minimum string value\n",
61 | " This can be done using the min() along with a value\n",
62 | "Author: Tanu Nanda Prabhu\n",
63 | "'''\n",
64 | "\n",
65 | "# Calling the mini() function by passing the string value\n",
66 | "minimum = min(\"programming\")\n",
67 | "print(minimum)"
68 | ],
69 | "execution_count": null,
70 | "outputs": []
71 | },
72 | {
73 | "cell_type": "markdown",
74 | "metadata": {
75 | "id": "U5rLUVOrDT6m"
76 | },
77 | "source": [
78 | "### **2) What is the output of the below code**\n",
79 | "1. p\n",
80 | "2. y\n",
81 | "3. t\n",
82 | "4. None of the above"
83 | ]
84 | },
85 | {
86 | "cell_type": "code",
87 | "metadata": {
88 | "id": "pL9shtJWDVd1"
89 | },
90 | "source": [
91 | "'''\n",
92 | "Program: 2\n",
93 | "Description: Finding the maximum string value\n",
94 | " This can be done using the max() along with a value\n",
95 | "Author: Tanu Nanda Prabhu\n",
96 | "'''\n",
97 | "\n",
98 | "# Calling the max() function by passing the string value\n",
99 | "maximum = max(\"python\")\n",
100 | "print(maximum)"
101 | ],
102 | "execution_count": null,
103 | "outputs": []
104 | },
105 | {
106 | "cell_type": "markdown",
107 | "metadata": {
108 | "id": "armkk8YfAvkh"
109 | },
110 | "source": [
111 | "### **3) What is the output of the below code**\n",
112 | "1. Success\n",
113 | "2. Failure\n",
114 | "3. Invalid Syntax\n",
115 | "4. None of the above"
116 | ]
117 | },
118 | {
119 | "cell_type": "code",
120 | "metadata": {
121 | "id": "56pUyW7_BBJL"
122 | },
123 | "source": [
124 | "'''\n",
125 | "Program: 3\n",
126 | "Description: Playing with '+' and increment operators in Python\n",
127 | "Author: Tanu Nanda Prabhu\n",
128 | "'''\n",
129 | "\n",
130 | "a = 7\n",
131 | "a1 = a + 1\n",
132 | "a2 = a++\n",
133 | "\n",
134 | "if a1 == a2:\n",
135 | " print(\"Success\")\n",
136 | "else:\n",
137 | " print(\"Failure\")\n"
138 | ],
139 | "execution_count": null,
140 | "outputs": []
141 | },
142 | {
143 | "cell_type": "markdown",
144 | "metadata": {
145 | "id": "GCCX3cZg0fZj"
146 | },
147 | "source": [
148 | "### **4) What is the output of the below code**\n",
149 | "1. Success\n",
150 | "2. Failure\n",
151 | "3. Invalid Syntax\n",
152 | "4. None of the above"
153 | ]
154 | },
155 | {
156 | "cell_type": "code",
157 | "metadata": {
158 | "id": "rue6_C0PzE2P"
159 | },
160 | "source": [
161 | "'''\n",
162 | "Program: 4\n",
163 | "Description: Playing with increment and decrement operators in Python\n",
164 | "Author: Tanu Nanda Prabhu\n",
165 | "'''\n",
166 | "\n",
167 | "a = 7\n",
168 | "a1 = 0\n",
169 | "a2 = 0\n",
170 | "a1 += 1\n",
171 | "a2 -= 1\n",
172 | "\n",
173 | "if a1 == a2:\n",
174 | " print(\"Success\")\n",
175 | "else:\n",
176 | " print(\"Failure\")\n"
177 | ],
178 | "execution_count": null,
179 | "outputs": []
180 | },
181 | {
182 | "cell_type": "markdown",
183 | "metadata": {
184 | "id": "9bdahV4t-PIf"
185 | },
186 | "source": [
187 | "### **5) What is the output of the below code**\n",
188 | "1. a a a\n",
189 | "2. a1 a2 a3\n",
190 | "3. 1 2 3\n",
191 | "4. None of the above"
192 | ]
193 | },
194 | {
195 | "cell_type": "code",
196 | "metadata": {
197 | "id": "RpZ2dMgd-Nim"
198 | },
199 | "source": [
200 | "'''\n",
201 | "Program: 5\n",
202 | "Description: Performing list operations\n",
203 | " \n",
204 | "Author: Tanu Nanda Prabhu\n",
205 | "'''\n",
206 | "\n",
207 | "l = {'a1':\"1\", 'a2': \"2\", 'a3':\"3\"}\n",
208 | "for x, y in l:\n",
209 | " print(x[0], end = \" \")"
210 | ],
211 | "execution_count": null,
212 | "outputs": []
213 | },
214 | {
215 | "cell_type": "markdown",
216 | "metadata": {
217 | "id": "fngzOp_mclgr"
218 | },
219 | "source": [
220 | "\n",
221 | "\n",
222 | "---\n",
223 | "\n",
224 | "\n",
225 | "\n",
226 | "### **6) What is the output of the below code**\n",
227 | "1. a a a\n",
228 | "2. a1 a2 a3\n",
229 | "3. 1 2 3\n",
230 | "4. None of the above"
231 | ]
232 | },
233 | {
234 | "cell_type": "code",
235 | "metadata": {
236 | "id": "wzh-fAcFcZFX"
237 | },
238 | "source": [
239 | "'''\n",
240 | "Program: 6\n",
241 | "Description: Performing list operations\n",
242 | " \n",
243 | "Author: Tanu Nanda Prabhu\n",
244 | "'''\n",
245 | "\n",
246 | "l = {'a1':\"1\", 'a2': \"2\", 'a3':\"3\"}\n",
247 | "for x in l:\n",
248 | " print(x[1], end = \" \")"
249 | ],
250 | "execution_count": null,
251 | "outputs": []
252 | },
253 | {
254 | "cell_type": "markdown",
255 | "metadata": {
256 | "id": "L1L3zuaUcrRH"
257 | },
258 | "source": [
259 | "\n",
260 | "\n",
261 | "\n",
262 | "---\n",
263 | "\n",
264 | "\n",
265 | "\n",
266 | "### **7) What is the output of the below code**\n",
267 | "1. a a a\n",
268 | "2. a1 a2 a3\n",
269 | "3. 1 2 3\n",
270 | "4. None of the above"
271 | ]
272 | },
273 | {
274 | "cell_type": "code",
275 | "metadata": {
276 | "id": "8NEadcp4dzQz"
277 | },
278 | "source": [
279 | "'''\n",
280 | "Program: 7\n",
281 | "Description: Performing list operations\n",
282 | " \n",
283 | "Author: Tanu Nanda Prabhu\n",
284 | "'''\n",
285 | "\n",
286 | "l = {'a1':\"1\", 'a2': \"2\", 'a3':\"3\"}\n",
287 | "for x in l:\n",
288 | " print(x, end = \" \")"
289 | ],
290 | "execution_count": null,
291 | "outputs": []
292 | },
293 | {
294 | "cell_type": "markdown",
295 | "metadata": {
296 | "id": "mo_7cfh60ZVP"
297 | },
298 | "source": [
299 | "---\n",
300 | "\n",
301 | "### **8) What is the output of the below code**\n",
302 | "1. e\n",
303 | "2. The\n",
304 | "3. T\n",
305 | "4. Invalid Index"
306 | ]
307 | },
308 | {
309 | "cell_type": "code",
310 | "metadata": {
311 | "id": "imALsSVb0Yo0"
312 | },
313 | "source": [
314 | "'''\n",
315 | "Program: 8\n",
316 | "Description: Performing list operations using index\n",
317 | " \n",
318 | "Author: Tanu Nanda Prabhu\n",
319 | "'''\n",
320 | "\n",
321 | "l = [\"Every\", 1, \"Can't\", \"Be\", \"The\", \"Best\", 1]\n",
322 | "print(l[4][2])"
323 | ],
324 | "execution_count": null,
325 | "outputs": []
326 | },
327 | {
328 | "cell_type": "markdown",
329 | "metadata": {
330 | "id": "jFqGfS6FM5EQ"
331 | },
332 | "source": [
333 | "\n",
334 | "\n",
335 | "---\n",
336 | "\n",
337 | "### **9) What is the output of the below code**\n",
338 | "1. 9\n",
339 | "2. 9.0\n",
340 | "3. 8.9\n",
341 | "4. Invalid Syntax\n",
342 | "\n"
343 | ]
344 | },
345 | {
346 | "cell_type": "code",
347 | "metadata": {
348 | "id": "Rwf25sRVM9ER"
349 | },
350 | "source": [
351 | "'''\n",
352 | "Program: 9\n",
353 | "Description: Performing quick mathematics using Python\n",
354 | " \n",
355 | "Author: Tanu Nanda Prabhu\n",
356 | "'''\n",
357 | "\n",
358 | "value = 6/2*(1+2)\n",
359 | "print(value)"
360 | ],
361 | "execution_count": null,
362 | "outputs": []
363 | },
364 | {
365 | "cell_type": "markdown",
366 | "metadata": {
367 | "id": "uEpO9d5MaWvP"
368 | },
369 | "source": [
370 | "\r\n",
371 | "\r\n",
372 | "---\r\n",
373 | "\r\n",
374 | "### **10) What is the output of the below code**\r\n",
375 | "1. 7\r\n",
376 | "2. 7.0\r\n",
377 | "3. 6\r\n",
378 | ".9\r\n",
379 | "4. Invalid Syntax\r\n",
380 | "\r\n"
381 | ]
382 | },
383 | {
384 | "cell_type": "code",
385 | "metadata": {
386 | "id": "leL_YoDEZ_F0"
387 | },
388 | "source": [
389 | "'''\r\n",
390 | "Program: 10\r\n",
391 | "Description: Performing quick mathematics using eval\r\n",
392 | " \r\n",
393 | "Author: Tanu Nanda Prabhu\r\n",
394 | "'''\r\n",
395 | "\r\n",
396 | "value = ('1 + 3 * 2')\r\n",
397 | "print(eval(value))"
398 | ],
399 | "execution_count": null,
400 | "outputs": []
401 | },
402 | {
403 | "cell_type": "markdown",
404 | "metadata": {
405 | "id": "f4BF_DYsc3B5"
406 | },
407 | "source": [
408 | "\r\n",
409 | "\r\n",
410 | "---\r\n",
411 | "\r\n"
412 | ]
413 | }
414 | ]
415 | }
--------------------------------------------------------------------------------
/Quiz/Python_Quiz_3.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Python-Quiz-3.ipynb",
7 | "provenance": [],
8 | "collapsed_sections": [],
9 | "authorship_tag": "ABX9TyM/Qu7TbGCer7NFgPgTuiss",
10 | "include_colab_link": true
11 | },
12 | "kernelspec": {
13 | "name": "python3",
14 | "display_name": "Python 3"
15 | }
16 | },
17 | "cells": [
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "view-in-github",
22 | "colab_type": "text"
23 | },
24 | "source": [
25 | "
"
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {
31 | "id": "dTrLdq0JuBaP"
32 | },
33 | "source": [
34 | "# **Python Basics - Quiz-3**\r\n",
35 | "\r\n",
36 | "## **Use this to enhance to your python skill**"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {
42 | "id": "Wo-eRv2ZuGYm"
43 | },
44 | "source": [
45 | "### **1) What is the output of the below code**\r\n",
46 | "1. 2019\r\n",
47 | "2. 39\r\n",
48 | "3. 20 19\r\n",
49 | "4. None of the above"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "metadata": {
55 | "id": "J7BLSbSQuCsV"
56 | },
57 | "source": [
58 | "'''\r\n",
59 | "Program: 1\r\n",
60 | "Description: Playing with strings using \"+\"\r\n",
61 | "Author: Tanu Nanda Prabhu\r\n",
62 | "'''\r\n",
63 | "\r\n",
64 | "value = 20\r\n",
65 | "value2 = 19\r\n",
66 | "\r\n",
67 | "result = int('%d%d' % (value, value2))\r\n",
68 | "print(result)"
69 | ],
70 | "execution_count": null,
71 | "outputs": []
72 | },
73 | {
74 | "cell_type": "markdown",
75 | "metadata": {
76 | "id": "JMYIbJwa1X0R"
77 | },
78 | "source": [
79 | "### **2) What is the output of the below code**\r\n",
80 | "1. 2020\r\n",
81 | "2. 40\r\n",
82 | "3. 20 20\r\n",
83 | "4. None of the above"
84 | ]
85 | },
86 | {
87 | "cell_type": "code",
88 | "metadata": {
89 | "id": "RckEQBTp1YlO"
90 | },
91 | "source": [
92 | "'''\r\n",
93 | "Program: 2\r\n",
94 | "Description: Playing with strings using \"+\"\r\n",
95 | "Author: Tanu Nanda Prabhu\r\n",
96 | "'''\r\n",
97 | "\r\n",
98 | "value = '20'\r\n",
99 | "value2 = '20'\r\n",
100 | "\r\n",
101 | "result = (int(value) + int(value2))\r\n",
102 | "print(result)"
103 | ],
104 | "execution_count": null,
105 | "outputs": []
106 | },
107 | {
108 | "cell_type": "markdown",
109 | "metadata": {
110 | "id": "1doH8ODTzrog"
111 | },
112 | "source": [
113 | "### **3) What is the output of the below code**\r\n",
114 | "1. 65\r\n",
115 | "2. 97\r\n",
116 | "3. Invalid Syntax\r\n",
117 | "4. None of the above"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "metadata": {
123 | "id": "422UQhH4ztsb"
124 | },
125 | "source": [
126 | "'''\r\n",
127 | "Program: 3\r\n",
128 | "Description: Playing with characters\r\n",
129 | "Author: Tanu Nanda Prabhu\r\n",
130 | "'''\r\n",
131 | "\r\n",
132 | "char = 'A'\r\n",
133 | "print(ord(char))"
134 | ],
135 | "execution_count": null,
136 | "outputs": []
137 | },
138 | {
139 | "cell_type": "markdown",
140 | "metadata": {
141 | "id": "eYmcuP3ZvEa9"
142 | },
143 | "source": [
144 | "### **4) What is the output of the below code**\r\n",
145 | "1. abc1abc2abc3\r\n",
146 | "2. 1abc2abc3\r\n",
147 | "3. Invalid Syntax\r\n",
148 | "4. None of the above"
149 | ]
150 | },
151 | {
152 | "cell_type": "code",
153 | "metadata": {
154 | "id": "K5iOlAAAvF-0"
155 | },
156 | "source": [
157 | "'''\r\n",
158 | "Program: 4\r\n",
159 | "Description: Playing with join method\r\n",
160 | "Author: Tanu Nanda Prabhu\r\n",
161 | "'''\r\n",
162 | "\r\n",
163 | "s1 = 'abc'\r\n",
164 | "s2 = '123'\r\n",
165 | "print(s1.join(s2))"
166 | ],
167 | "execution_count": null,
168 | "outputs": []
169 | },
170 | {
171 | "cell_type": "markdown",
172 | "metadata": {
173 | "id": "oxiiSN25A6nx"
174 | },
175 | "source": [
176 | "### **5) What is the output of the below code**\r\n",
177 | "1. True\r\n",
178 | "2. False\r\n",
179 | "3. Invalid Syntax\r\n",
180 | "4. None of the above"
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "metadata": {
186 | "id": "UYGj4U3MA7ql"
187 | },
188 | "source": [
189 | "'''\r\n",
190 | "Program: 5\r\n",
191 | "Author: Tanu Nanda Prabhu\r\n",
192 | "'''\r\n",
193 | "\r\n",
194 | "str1, str2 = \"Python\", \"Python\"\r\n",
195 | "\r\n",
196 | "print(\"id of str1 is: \", id(str1))\r\n",
197 | "print(\"id of str2 is: \", id(str2))\r\n",
198 | "\r\n",
199 | "if id(str1) == id(str2):\r\n",
200 | " print(\"True\")\r\n",
201 | "else:\r\n",
202 | " print(\"False\")"
203 | ],
204 | "execution_count": null,
205 | "outputs": []
206 | },
207 | {
208 | "cell_type": "markdown",
209 | "metadata": {
210 | "id": "tpG4KQUvWe-0"
211 | },
212 | "source": [
213 | "\r\n",
214 | "\r\n",
215 | "---\r\n",
216 | "\r\n",
217 | "\r\n",
218 | "### **6) What is the output of the below code**\r\n",
219 | "1. ``\r\n",
220 | "2. `<'set'>`\r\n",
221 | "3. `set`\r\n",
222 | "4. None of the above\r\n",
223 | "\r\n"
224 | ]
225 | },
226 | {
227 | "cell_type": "code",
228 | "metadata": {
229 | "id": "lEbdKfs6WjEu"
230 | },
231 | "source": [
232 | "'''\r\n",
233 | "Program: 6\r\n",
234 | "Author: Tanu Nanda Prabhu\r\n",
235 | "'''\r\n",
236 | "\r\n",
237 | "val = set()\r\n",
238 | "print(type(val))"
239 | ],
240 | "execution_count": null,
241 | "outputs": []
242 | },
243 | {
244 | "cell_type": "markdown",
245 | "metadata": {
246 | "id": "P-NRVKgUiO_6"
247 | },
248 | "source": [
249 | "\r\n",
250 | "\r\n",
251 | "---\r\n",
252 | "\r\n",
253 | "\r\n",
254 | "### **7) What is the output of the below code**\r\n",
255 | "1. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\n",
256 | "2. [7, 9, 11, 13, 15]\r\n",
257 | "3. Lists cannot be added\r\n",
258 | "4. None of the above\r\n",
259 | "\r\n"
260 | ]
261 | },
262 | {
263 | "cell_type": "code",
264 | "metadata": {
265 | "id": "CnzlXrCch8Ik"
266 | },
267 | "source": [
268 | "'''\r\n",
269 | "Program: 7\r\n",
270 | "Author: Tanu Nanda Prabhu\r\n",
271 | "'''\r\n",
272 | "\r\n",
273 | "# Playing with Lists in Python\r\n",
274 | "\r\n",
275 | "lis = [1, 2, 3, 4, 5]\r\n",
276 | "lis2 = [6, 7, 8, 9, 10]\r\n",
277 | "\r\n",
278 | "print(lis+lis2)"
279 | ],
280 | "execution_count": null,
281 | "outputs": []
282 | },
283 | {
284 | "cell_type": "markdown",
285 | "metadata": {
286 | "id": "V6LdTLqz_gwQ"
287 | },
288 | "source": [
289 | "\r\n",
290 | "\r\n",
291 | "---\r\n",
292 | "\r\n",
293 | "\r\n",
294 | "### **8) What is the output of the below code**\r\n",
295 | "1. True\r\n",
296 | "2. False\r\n",
297 | "3. Invalid Syntax\r\n",
298 | "4. None of the above\r\n",
299 | "\r\n"
300 | ]
301 | },
302 | {
303 | "cell_type": "code",
304 | "metadata": {
305 | "id": "Y6BQNgeO-vdW"
306 | },
307 | "source": [
308 | "'''\r\n",
309 | "Program: 8\r\n",
310 | "Description: Using str.lower() method\r\n",
311 | "Author: Tanu Nanda Prabhu\r\n",
312 | "'''\r\n",
313 | "\r\n",
314 | "str1 = \"pythoN\"\r\n",
315 | "str2 = str1.lower()\r\n",
316 | "print(str1 == str2)"
317 | ],
318 | "execution_count": null,
319 | "outputs": []
320 | },
321 | {
322 | "cell_type": "markdown",
323 | "metadata": {
324 | "id": "f3ckANrOUJEC"
325 | },
326 | "source": [
327 | "\r\n",
328 | "\r\n",
329 | "\r\n",
330 | "\r\n",
331 | "\r\n",
332 | "---\r\n",
333 | "\r\n",
334 | "\r\n",
335 | "### **9) What is the output of the below code**\r\n",
336 | "1. `['P', 'y', 't', 'h', 'o', 'n'] `\r\n",
337 | "2. `['P', 'y', 't', 'h', 'o', 'n'] `\r\n",
338 | "3. `Python `\r\n",
339 | "4. `Python `\r\n",
340 | "\r\n"
341 | ]
342 | },
343 | {
344 | "cell_type": "code",
345 | "metadata": {
346 | "id": "EabI5zplbBq3"
347 | },
348 | "source": [
349 | "'''\r\n",
350 | "Program: 9\r\n",
351 | "Description: Typecasting the variable\r\n",
352 | "Author: Tanu Nanda Prabhu\r\n",
353 | "'''\r\n",
354 | "\r\n",
355 | "val = \"Python\"\r\n",
356 | "\r\n",
357 | "result = ''.join(list(val))\r\n",
358 | "print(result, type(result))"
359 | ],
360 | "execution_count": null,
361 | "outputs": []
362 | },
363 | {
364 | "cell_type": "markdown",
365 | "metadata": {
366 | "id": "x2MY8g_afHrX"
367 | },
368 | "source": [
369 | "---\r\n",
370 | "\r\n",
371 | "### **10) What is the output of the below code**\r\n",
372 | "1. 3\r\n",
373 | "2. 6\r\n",
374 | "3. 0\r\n",
375 | "4. `Invalid Syntax - Index Can't be Multiplied`\r\n"
376 | ]
377 | },
378 | {
379 | "cell_type": "code",
380 | "metadata": {
381 | "id": "dKxhCZbPelXl"
382 | },
383 | "source": [
384 | "'''\r\n",
385 | "Program: 10\r\n",
386 | "Description: List index method\r\n",
387 | "Author: Tanu Nanda Prabhu\r\n",
388 | "'''\r\n",
389 | "\r\n",
390 | "lis = ['Python', 'Programming', 'Rocks'] \r\n",
391 | "pos = lis.index(\"Rocks\") \r\n",
392 | "print(pos * 3)"
393 | ],
394 | "execution_count": null,
395 | "outputs": []
396 | },
397 | {
398 | "cell_type": "markdown",
399 | "metadata": {
400 | "id": "zSbFiCEQfiy1"
401 | },
402 | "source": [
403 | "\r\n",
404 | "\r\n",
405 | "---\r\n",
406 | "\r\n"
407 | ]
408 | }
409 | ]
410 | }
--------------------------------------------------------------------------------
/Speech_Recognition_using_Python.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Speech Recognition using Python.ipynb",
7 | "provenance": [],
8 | "authorship_tag": "ABX9TyOV6ZOV/eO+H5GybBKIl3a0",
9 | "include_colab_link": true
10 | },
11 | "kernelspec": {
12 | "name": "python3",
13 | "display_name": "Python 3"
14 | }
15 | },
16 | "cells": [
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "id": "view-in-github",
21 | "colab_type": "text"
22 | },
23 | "source": [
24 | "
"
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {
30 | "id": "HeljZdx2oSCe",
31 | "colab_type": "text"
32 | },
33 | "source": [
34 | "# Speech Recognition using Python\n",
35 | "\n",
36 | "\n",
37 | "## In this tutorial, I will develop a speech recognition system using python from scratch using necessary libraries.\n",
38 | "\n",
39 | "\n",
40 | "\n",
41 | "Before getting started there are some necessary tools that you need to download and install to successfully complete this tutorial.\n"
42 | ]
43 | },
44 | {
45 | "cell_type": "markdown",
46 | "metadata": {
47 | "id": "UQ9BYp4ZodwQ",
48 | "colab_type": "text"
49 | },
50 | "source": [
51 | "## Necessary tools required for the tutorial:\n",
52 | "\n",
53 | "* **Python** → Just go to your command prompt and type `python -V` (Capital V). When you hit enter, it will prompt you the latest version of python and make sure it says `Python 3.8.1` . It is the latest version of Python for Windows (I literally downloaded it yesterday). If you have some other versions, just uninstall and [download](https://www.python.org/downloads/) a new one. Just do it, I will let you know the reason later.\n",
54 | "\n",
55 | "Now in the second case if you get a message something like this `Python is not an internal or an external command`. With no further due, take a deep breath and download Python from [here](https://www.python.org/downloads/).\n",
56 | "\n",
57 | "* **Visual Studio Code** → This is one of my favorite python code editors. Just download this to get a better programming experience with the rich features. Don’t worry, I’m not advertising (I wish I was). Anyway, one of the best things I like about the VS Code is that it has a built-in terminal. Every time if you want to install any external python libraries, you can use that built-in terminal to do the installation. You can skip a step of going to the command prompt. To download the Visual Studio Code, please use this [link](https://code.visualstudio.com/download). If you get stuck somewhere, don’t worry, I got you. Follow the [YouTube video](https://www.youtube.com/watch?v=E9U-EBG8jVk&t=88s) to get a better understanding.\n",
58 | "\n",
59 | "* **Speech Recognition library** → Now that you have installed and spent some time with the IDE (Visual Studio Code). It’s time to install some libraries inside the Visual Studion Terminal. Just type `pip install SpeechRecognition`. To read more about this library, the [documentation](https://pypi.org/project/SpeechRecognition/) is always available.\n",
60 | "\n",
61 | "\n",
62 | "\n",
63 | "\n",
64 | "* **PyAudio library**→ Basically, it is a cross-platform [audio/video library](https://pypi.org/project/PyAudio/). Since we are dealing with the audio in this tutorial, we need to install it. Also, if we want to use our device’s microphone for input, then we need to install PyAudio. Now install the library might be tremendously hard. Especially if it is windows. Believe me, I have taken 5 straight hours installing it. Although it is not just typing, `pip install PyAudio` in the command prompt. If you are lucky, then it might work but if you are unlucky individual like me, you will get an error message as shown below:\n",
65 | "\n",
66 | "\n",
67 | "\n",
68 | "So I somehow discovered an alternate way to install the library. I could do this with the help of a [YouTube](https://www.youtube.com/watch?v=AKymlea8sYM) video. Special thanks to the creator of this video. Please see the above video for a successful installation.\n",
69 | "\n",
70 | "If you are not OK with watching a video, don’t worry I got you. Just follow the steps given down below:\n",
71 | "\n",
72 | "* Download the [PyAudio](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio) file from the “[Unofficial Windows Binaries for Python Extension Packages](https://www.lfd.uci.edu/~gohlke/pythonlibs/)”, thanks to [Christoph Gohlke](https://www.lfd.uci.edu/~gohlke/), [Laboratory for Fluorescence Dynamics](https://www.lfd.uci.edu/), [University of California](https://www.uci.edu/), Irvine. To access the link, just click [here](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio). Also, if your version of Python is something like 3.8.1 then download the file which has the name “**PyAudio-0.2.11-cp38-cp38-win32.whl**”. The second one from the top. But the whole point here is both the version of the PyAudio, and the Python must be the same.\n",
73 | "\n",
74 | "\n",
75 | "* Press “**Run**” below the search bar. Or ask Cortona or Google for help. Make sure you type `%appdata%` in the run command prompt. It will look something like shown below:\n",
76 | "\n",
77 | "\n",
78 | "\n",
79 | "* As soon as you click OK from the Run command prompt. It will redirect you inside the app data of your computer. I will look something like this.\n",
80 | "\n",
81 | "\n",
82 | "\n",
83 | "Make sure you go back until you get “Local”, “LocalLow”, Roaming”. Click on **Local**.\n",
84 | "\n",
85 | "* Click on ***Programs → Python →Python 38–32 → Scripts →Paste the downloaded file (PyAudio)*** inside the Scripts folder.\n",
86 | "\n",
87 | "## To summarize\n",
88 | "\n",
89 | "C:\\Users\\tanup\\AppData\\Local\\Programs\\Python\\Python38–32\\Script (This is in my case).\n",
90 | "\n",
91 | "\n",
92 | "\n",
93 | "* And this is an important step. Here you need to select the file and then get the path from the bar above as shown in the below:\n",
94 | "\n",
95 | "![alt text] (https://miro.medium.com/max/1215/1*G0yu9p50QXDVsVyXm_BAvg.png)\n",
96 | "\n",
97 | "Copy the above path we will need it in the below step.\n",
98 | "\n",
99 | "* The last step and the easiest step now is to install the library manually. Now just to your command and type the below command.\n",
100 | "\n",
101 | "pip install C:\\Users\\tanup\\AppData\\Local\\Programs\\Python\\Python38–32\\Scripts\\PyAudio-0.2.11-cp38-cp38-win32.whl\n",
102 | "\n",
103 | "```\n",
104 | "pip install C:\\Users\\tanup\\AppData\\Local\\Programs\\Python\\Python38–32\\Scripts\\PyAudio-0.2.11-cp38-cp38-win32.whl\n",
105 | "\n",
106 | "```\n",
107 | "\n",
108 | "Don’t freak out by seeing the command, it’s nothing but the pip install and the path where your PyAudio file is stored. Therefore, I told you to copy the path of the file.\n",
109 | "\n",
110 | "\n",
111 | "\n",
112 | "So once you see the success message then congratulations you have successfully installed the library the hard way. If you want to double-check your successful installation. Then type IDLE in the below the windows search bar and then type `import pyaudio`. If you have successfully installed the library, then you will get no errors.\n",
113 | "\n",
114 | "\n",
115 | "\n",
116 | "\n",
117 | "___\n",
118 | "\n",
119 | "## Its time to code now\n",
120 | "\n",
121 | "Finally, its time for us to code\n",
122 | "\n",
123 | "I would like to give the credits for the author of the code because I got the code from a [GitHub Repository](https://github.com/umangahuja1/Youtube/blob/master/Python_Extras/speech.py).\n",
124 | "\n",
125 | "\n",
126 | "\n",
127 | "\n"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "metadata": {
133 | "id": "pmUKZ3lcsk3E",
134 | "colab_type": "code",
135 | "colab": {}
136 | },
137 | "source": [
138 | "import speech_recognition as sr\n",
139 | "r = sr.Recognizer()\n",
140 | "with sr.Microphone() as source:\n",
141 | " print(\"Speak Anything :\")\n",
142 | " audio = r.listen(source)\n",
143 | " try:\n",
144 | " text = r.recognize_google(audio)\n",
145 | " print(\"You said : {}\".format(text))\n",
146 | " except:\n",
147 | " print(\"Sorry could not recognize what you said\")"
148 | ],
149 | "execution_count": 0,
150 | "outputs": []
151 | },
152 | {
153 | "cell_type": "markdown",
154 | "metadata": {
155 | "id": "nDPZSXtYq3Lm",
156 | "colab_type": "text"
157 | },
158 | "source": [
159 | "I will provide a brief explanation of the code:\n",
160 | "\n",
161 | "* Firstly import the library `speech_recognition`.\n",
162 | "* Then we need to recognize the speech. We need not write the recognizer function from scratch thanks to the library. All we need to do is with the help of `speech_recognizer` invoke a function called `Recognizer()`.\n",
163 | "* There are so many methods for recognizing the speech from an audio source. Choose the one that fits your needs (Just Kidding). Just use the one I’m showing. Some of the most common methods are:\n",
164 | "\n",
165 | "* `recognize_bing()` : Microsoft Bing Speech\n",
166 | "* `recognize_google()` : Google Web Speech\n",
167 | "* `recognize_google_cloud()` : Google Cloud Speech\n",
168 | "* `recognize_houndify()` : Houndify Speech\n",
169 | "* `recognize_ibm()` : IMB Speech\n",
170 | "* `recognize_wit()` : Wit.ai Speech\n",
171 | "\n",
172 | "In this tutorial, I will use the second method, i.e. `recognize_google()`. But make sure just executing this will cause an error because you need to provide an audio source. Now to get the audio source you have to listen to it right. Because the whole point is to listen to what the user says, and then display it. So in the code, so the method `listen` is used.\n",
173 | "\n",
174 | "* Once you have done, as shown above, the next step is to print the output. Meaning the system has listened to the user’s input, it should then display the output in a readable format.\n",
175 | "\n",
176 | "* Now last but not least. Executing the program is the only pending task. I bet if you have followed every line of this tutorial and all the installation process then you would not get any errors. But if you get any errors, you know what to do. Post it in the contacts section I’ll have a look and I shall look over it. If everything works, then let’s see the output.\n",
177 | "\n",
178 | "\n",
179 | "\n",
180 | "\n",
181 | "Now I don’t know if you noticed this or not. The moment you executed this program at the bottom corner of your laptop’s display, the microphone icon would be enabled. Meaning that it’s listening (Isn’t is freaky). I would pop up when the program is executed, and then it disappears.\n",
182 | "\n",
183 | "\n",
184 | "\n",
185 | "Now, this is not a great project or great invention, all we are doing is using the right libraries at the right time. Now, this is a good start for those who did not know that libraries can create wonders. Also, you have learned how to manually install a library. I hope you have enjoyed reading this tutorial. You learned something new today. Stay tuned for more updates. Until then, see you goodbye. Have a nice day.\n",
186 | "\n",
187 | "___\n",
188 | "\n",
189 | "\n",
190 | "\n"
191 | ]
192 | }
193 | ]
194 | }
--------------------------------------------------------------------------------
/Splitting_the_dataset_into_three_sets.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Splitting_the_dataset_into_three_sets.ipynb",
7 | "provenance": [],
8 | "collapsed_sections": [],
9 | "authorship_tag": "ABX9TyMzSplJ67qx8DafnGw4Iolb",
10 | "include_colab_link": true
11 | },
12 | "kernelspec": {
13 | "name": "python3",
14 | "display_name": "Python 3"
15 | }
16 | },
17 | "cells": [
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "view-in-github",
22 | "colab_type": "text"
23 | },
24 | "source": [
25 | "
"
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {
31 | "id": "sh0fLKZpdIp9",
32 | "colab_type": "text"
33 | },
34 | "source": [
35 | "# **Splitting the dataset into three sets**\n",
36 | "\n",
37 | "## **In this article, we will understand the necessity of splitting the data set.**\n",
38 | "\n",
39 | "\n",
40 | "\n"
41 | ]
42 | },
43 | {
44 | "cell_type": "markdown",
45 | "metadata": {
46 | "id": "zX_9DNXsdRJe",
47 | "colab_type": "text"
48 | },
49 | "source": [
50 | "# **Introduction**\n",
51 | "\n",
52 | "In this article, we will mainly focus on **why** do we need to split the dataset into three sets. If so, **how** do we do it?. All these days you have been blindly splitting the data into two sets. Let me guess the name of the sets:\n",
53 | "\n",
54 | "\n",
55 | "\n",
56 | "1. **Training set**\n",
57 | "2. **Testing set**\n",
58 | "\n",
59 | "You would have used the **training set data** to only **train or build your machine learning model or algorithm**. Similarly, the **testing set** to **evaluate or assess the performance of your model**.\n",
60 | "\n",
61 | "Splitting the data into two sets is not wrong. But don't you think you are putting too much burden on the testing set. Because in your case you will use the testing set to:\n",
62 | "\n",
63 | "\n",
64 | "\n",
65 | "1. **Evaluate the model**\n",
66 | "2. **Fine-tune the parameters (tuning) or choosing the best parameters**\n",
67 | "3. **Assess the model performance**\n",
68 | "\n",
69 | "Sometimes putting too much load on a donkey ain't gonna work out. Rather invest in a new donkey and put some load on it. This makes your life easy. So your next thought would be what's the splitting ratio. Well, the answer lies in the next section.\n",
70 | "\n",
71 | "---\n",
72 | "\n",
73 | "\n",
74 | "\n",
75 | "\n",
76 | "\n",
77 | "\n"
78 | ]
79 | },
80 | {
81 | "cell_type": "markdown",
82 | "metadata": {
83 | "id": "eMogI0b7eJ2d",
84 | "colab_type": "text"
85 | },
86 | "source": [
87 | "# **Three sets**\n",
88 | "\n",
89 | "Yes, you read it right its \"**Three sets**\". In practice, data analysts work with three distinct sets namely:\n",
90 | "\n",
91 | "\n",
92 | "1. Training set\n",
93 | "2. Testing set\n",
94 | "3. Validation set\n",
95 | "\n",
96 | "\n",
97 | "Let me explain this with the help of a made-up diagram (block diagram). Consider you have a \"**Car Dataset**\" which mainly comprises the features of the car such as model, brand, year, horsepower along with the price. Now your job is to **predict the price** of the car **given the features**. For example, if someone gives you all the features of the car you should take that information then do some magic (apply machine learning algorithms) and then tell them the price of that particular car.\n",
98 | "\n",
99 | "\n",
100 | "\n",
101 | "\n",
102 | "Now you need to split the dataset into three sets as shown above. Below are some of the important guidelines:\n",
103 | "\n",
104 | "1. First, you need to **shuffle** the samples. You can use `random_state = 42`. This will just shuffle the samples if the value is **0**, then the samples will not be shuffled.\n",
105 | "\n",
106 | "2. Split the data sets into **Training, Validation, and Testing sets**. Usually, the training set should be the **biggest one in terms of sample size**. The validation and the testing set also know as the **holdout sets** must be roughly of the **same size**. In general, the holdout sets must be smaller than the size of the training set.\n",
107 | "\n",
108 | "---\n",
109 | "\n"
110 | ]
111 | },
112 | {
113 | "cell_type": "markdown",
114 | "metadata": {
115 | "id": "k_k5yEsne5z9",
116 | "colab_type": "text"
117 | },
118 | "source": [
119 | "## **Why the name holdout sets?**\n",
120 | "\n",
121 | "\n",
122 | "This is because the learning algorithm cannot use the samples or examples from these two subsets to build or train the model. Meaning for training the model you need to only use the training set samples.\n",
123 | "\n",
124 | "---"
125 | ]
126 | },
127 | {
128 | "cell_type": "markdown",
129 | "metadata": {
130 | "id": "b8ZIrJMbfBVJ",
131 | "colab_type": "text"
132 | },
133 | "source": [
134 | "## **What's the exact proportion of splitting?**\n",
135 | "\n",
136 | "\n",
137 | "There is no exact number for the splitting. If you are dealing with the big data sets you have over **500, 000 samples** or more, then in your case you use **95%** of the samples for training, **2.5%** for the validation, and the last **2.5%** for testing. However, if you don't have many samples, then you can split the dataset as **70+15+15**.\n",
138 | "\n",
139 | "---"
140 | ]
141 | },
142 | {
143 | "cell_type": "markdown",
144 | "metadata": {
145 | "id": "Ix7PojxTfPZ0",
146 | "colab_type": "text"
147 | },
148 | "source": [
149 | "## **What is the main reason behind the three sets?**\n",
150 | "\n",
151 | "\n",
152 | "One of the main purposes is that when we build or train the model there is no point in predicting the samples that the model has already seen. In this case, the model tries to memorize all the samples and makes no mistakes in predicting the samples. So no matter any machine learning algorithm you apply on predicting the training samples, the **accuracy will be higher** (over **95%**). Such algorithms will be useless in practice. Therefore, we want a model that is good at predicting the samples that the model has never seen before. This is what we need in the real world. This is why we need three sets and not one.\n",
153 | "\n",
154 | "---\n"
155 | ]
156 | },
157 | {
158 | "cell_type": "markdown",
159 | "metadata": {
160 | "id": "k95UcAjIfYA1",
161 | "colab_type": "text"
162 | },
163 | "source": [
164 | "## **What is the purpose of the hold-out sets?**\n",
165 | "\n",
166 | "\n",
167 | "Remember to follow these three thumb rules throughout your data science journey. From today please use:\n",
168 | "\n",
169 | "1. Training set to only **train** the model.\n",
170 | "2. Validation set to **choose the learning algorithm** and **choose or find the best hyperparameter**.\n",
171 | "3. Testing set to **assess or evaluate** the model before putting it into production.\n",
172 | "\n",
173 | "---"
174 | ]
175 | },
176 | {
177 | "cell_type": "markdown",
178 | "metadata": {
179 | "id": "Sp_2mlz2fr0a",
180 | "colab_type": "text"
181 | },
182 | "source": [
183 | "## **How to split the data set into three sets?**\n",
184 | "\n",
185 | "\n",
186 | "Well, there are quite a lot of solutions on the internet. My two favorite ones are:\n",
187 | "\n",
188 | "**Using the numpy library to split the data into three sets:**\n",
189 | "\n",
190 | "The below-given code will split the data into **60% of training**, **20% of the samples into validation**, and the rest **20% into the testing set**. Thanks to the [split method](https://docs.scipy.org/doc/numpy/reference/generated/numpy.split.html)."
191 | ]
192 | },
193 | {
194 | "cell_type": "code",
195 | "metadata": {
196 | "id": "ojx4SWbNf-N0",
197 | "colab_type": "code",
198 | "colab": {}
199 | },
200 | "source": [
201 | "train, validate, test = np.split(df.sample(frac=1), [int(.6*len(df)), int(.8*len(df))]"
202 | ],
203 | "execution_count": 0,
204 | "outputs": []
205 | },
206 | {
207 | "cell_type": "markdown",
208 | "metadata": {
209 | "id": "1yHJ_lFNf-4Z",
210 | "colab_type": "text"
211 | },
212 | "source": [
213 | "**Using the sklearn train test split method to split the data into three sets:**\n",
214 | "\n",
215 | "\n",
216 | "We can use the `sklearn.model_selection.train_test_split` twice to split the data set into three sets. First to split to train, test, and then split train again into validation and train. Thanks to the [sklearn library](http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html). In this case, the split will be **80+10+10**.\n"
217 | ]
218 | },
219 | {
220 | "cell_type": "code",
221 | "metadata": {
222 | "id": "dnT8b-YAgHyN",
223 | "colab_type": "code",
224 | "colab": {}
225 | },
226 | "source": [
227 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=1)\n",
228 | "\n",
229 | "X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.15, random_state=1) # 0.25 x 0.8 = 0.2"
230 | ],
231 | "execution_count": 0,
232 | "outputs": []
233 | },
234 | {
235 | "cell_type": "markdown",
236 | "metadata": {
237 | "id": "xFHcqT33gSwX",
238 | "colab_type": "text"
239 | },
240 | "source": [
241 | "\n",
242 | "\n",
243 | "---\n",
244 | "\n"
245 | ]
246 | },
247 | {
248 | "cell_type": "markdown",
249 | "metadata": {
250 | "id": "ukgX7yrTgTnG",
251 | "colab_type": "text"
252 | },
253 | "source": [
254 | "That's it for today, you guys have reached the end of the article. I hope you guys learned something new today. I used the [textbook](http://themlbook.com/) named \"**[The Hundred-Page Machine Learning Book by Andriy Burkov](http://themlbook.com/)**\" as a reference (Chapter 5) to write this tutorial. You can have a look at it. If you guys have any doubts regarding this tutorial, you can use the comment section down below. I will try to answer it as soon as possible. Until then, Stay Safe, Good Bye.\n",
255 | "\n",
256 | "---"
257 | ]
258 | }
259 | ]
260 | }
--------------------------------------------------------------------------------
/Src/Section1_Introduction.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Section1.ipynb",
7 | "provenance": [],
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | }
14 | },
15 | "cells": [
16 | {
17 | "cell_type": "markdown",
18 | "metadata": {
19 | "id": "view-in-github",
20 | "colab_type": "text"
21 | },
22 | "source": [
23 | "
"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {
29 | "id": "EbY2FS7z6ZyV",
30 | "colab_type": "text"
31 | },
32 | "source": [
33 | "# Python For Beginners "
34 | ]
35 | },
36 | {
37 | "cell_type": "markdown",
38 | "metadata": {
39 | "id": "ySn16e_D6dm5",
40 | "colab_type": "text"
41 | },
42 | "source": [
43 | "\n"
44 | ]
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "metadata": {
49 | "id": "QOsNQAl36hGT",
50 | "colab_type": "text"
51 | },
52 | "source": [
53 | "# Section 1: Introduction"
54 | ]
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {
59 | "id": "kxnm8bmc6exd",
60 | "colab_type": "text"
61 | },
62 | "source": [
63 | "In this tutorial I will teach you guys python from a beginners perspective. If you guys want to know about Python and study the theory behind it then read the [documentation](https://www.python.org/). There is no point of me explaining the definition and giving introduction about Python. All you need to know given the problem what approach you should take in order to solve the problem.\n",
64 | "\n",
65 | "The introduction section contains only the installation procedures of python and its IDE, but I strongly recommend you guys to just use Notebooks instead. Yes you heard it right be a professional coder and start working in notebooks. Here throughout the tutorial I'll be using the [Google Colab](https://colab.research.google.com/notebooks/welcome.ipynb) notebook to type all my code, it's a really good notebook to type the code and so that I can focus on documentation. If you use Google Colab you don't have to install nothing no Python, no IDE and no external libraries etc. Let's start coding. "
66 | ]
67 | }
68 | ]
69 | }
70 |
--------------------------------------------------------------------------------
/Src/Section2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Section2.ipynb",
7 | "provenance": [],
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | }
14 | },
15 | "cells": [
16 | {
17 | "cell_type": "markdown",
18 | "metadata": {
19 | "id": "view-in-github",
20 | "colab_type": "text"
21 | },
22 | "source": [
23 | "
"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {
29 | "id": "-LXPbirj6_zH",
30 | "colab_type": "text"
31 | },
32 | "source": [
33 | "# Section 2: Python Basics"
34 | ]
35 | },
36 | {
37 | "cell_type": "markdown",
38 | "metadata": {
39 | "id": "AkkJ7uwG7klL",
40 | "colab_type": "text"
41 | },
42 | "source": [
43 | ""
44 | ]
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "metadata": {
49 | "id": "S7SFMRLM7AbN",
50 | "colab_type": "text"
51 | },
52 | "source": [
53 | "## 1. Variables and data types\n",
54 | "\n",
55 | "A variable is a name of the memory location where we store the data. For example think of box where you store all you belongings inside that box. \n"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "metadata": {
61 | "id": "cUWE7e3u7Dqu",
62 | "colab_type": "code",
63 | "colab": {}
64 | },
65 | "source": [
66 | "# Creating a bunch of variables with mixture of datatypes like int, float, boolean.\n",
67 | "var = 20 # Integer data\n",
68 | "var1 = 20.0 # Float data\n",
69 | "var2 = False # Boolean data\n",
70 | "var3 = -20 # Integer data"
71 | ],
72 | "execution_count": 0,
73 | "outputs": []
74 | },
75 | {
76 | "cell_type": "code",
77 | "metadata": {
78 | "id": "QpgAsB0Q7FWM",
79 | "colab_type": "code",
80 | "colab": {
81 | "base_uri": "https://localhost:8080/",
82 | "height": 139
83 | },
84 | "outputId": "1de99ff2-8473-48d7-a5df-6e4877f460a8"
85 | },
86 | "source": [
87 | "# Printing the variables \n",
88 | "\n",
89 | "print(var)\n",
90 | "print(\"-------------------------------------------------------------\")\n",
91 | "print(var1)\n",
92 | "print(\"-------------------------------------------------------------\")\n",
93 | "print(var2)\n",
94 | "print(\"-------------------------------------------------------------\")\n",
95 | "print(var3)"
96 | ],
97 | "execution_count": 8,
98 | "outputs": [
99 | {
100 | "output_type": "stream",
101 | "text": [
102 | "20\n",
103 | "-------------------------------------------------------------\n",
104 | "20.0\n",
105 | "-------------------------------------------------------------\n",
106 | "False\n",
107 | "-------------------------------------------------------------\n",
108 | "-20\n"
109 | ],
110 | "name": "stdout"
111 | }
112 | ]
113 | },
114 | {
115 | "cell_type": "markdown",
116 | "metadata": {
117 | "id": "5iqRB58Y7H5I",
118 | "colab_type": "text"
119 | },
120 | "source": [
121 | "A datatype refers to the type of data that we store inside a variable. For example we store integer datatype, float datatype and booleab datatype. \n"
122 | ]
123 | },
124 | {
125 | "cell_type": "code",
126 | "metadata": {
127 | "id": "L8mXWd-k7JKH",
128 | "colab_type": "code",
129 | "colab": {
130 | "base_uri": "https://localhost:8080/",
131 | "height": 139
132 | },
133 | "outputId": "82cd4b34-91a0-4a40-bdad-f9f1bdeb3713"
134 | },
135 | "source": [
136 | "# The type of the data can be determined by using type() method.\n",
137 | "\n",
138 | "print(type(var))\n",
139 | "print(\"-------------------------------------------------------------\")\n",
140 | "print(type(var1))\n",
141 | "print(\"-------------------------------------------------------------\")\n",
142 | "print(type(var2))\n",
143 | "print(\"-------------------------------------------------------------\")\n",
144 | "print(type(var3))"
145 | ],
146 | "execution_count": 9,
147 | "outputs": [
148 | {
149 | "output_type": "stream",
150 | "text": [
151 | "\n",
152 | "-------------------------------------------------------------\n",
153 | "\n",
154 | "-------------------------------------------------------------\n",
155 | "\n",
156 | "-------------------------------------------------------------\n",
157 | "\n"
158 | ],
159 | "name": "stdout"
160 | }
161 | ]
162 | },
163 | {
164 | "cell_type": "markdown",
165 | "metadata": {
166 | "id": "ebMioqef7Vux",
167 | "colab_type": "text"
168 | },
169 | "source": [
170 | "\n",
171 | "\n",
172 | "---\n",
173 | "\n"
174 | ]
175 | },
176 | {
177 | "cell_type": "markdown",
178 | "metadata": {
179 | "id": "-reTM9zI7Lst",
180 | "colab_type": "text"
181 | },
182 | "source": [
183 | "## 2. Comments and Mathematical operators\n",
184 | "\n",
185 | "Comments are very useful especially when you are stuck in understanding the code with the help of comments ypu can understand the code.Single line comments can be written by using \"#\" . It's a good practice to comment your code."
186 | ]
187 | },
188 | {
189 | "cell_type": "code",
190 | "metadata": {
191 | "id": "cLmQahXA7Nib",
192 | "colab_type": "code",
193 | "colab": {}
194 | },
195 | "source": [
196 | "# This is a single line comment"
197 | ],
198 | "execution_count": 0,
199 | "outputs": []
200 | },
201 | {
202 | "cell_type": "markdown",
203 | "metadata": {
204 | "id": "Mo3Xzi__7PZ2",
205 | "colab_type": "text"
206 | },
207 | "source": [
208 | "Mathematical operators include additon, subtraction, multiplication, division etc. It is very easy to perform mathematical operations in python."
209 | ]
210 | },
211 | {
212 | "cell_type": "code",
213 | "metadata": {
214 | "id": "9BuhtN0X7Qer",
215 | "colab_type": "code",
216 | "colab": {}
217 | },
218 | "source": [
219 | "add = 10 + 5 # Addition\n",
220 | "sub = 10 - 5 # Subtraction\n",
221 | "mul = 10 * 5 # Multiplication\n",
222 | "div = 10 / 5 # Division\n",
223 | "exp = 10 ** 5 # Exponent\n",
224 | "floor = 13 // 5 # Floor division\n",
225 | "mod = 13 % 5 # Modulus operator"
226 | ],
227 | "execution_count": 0,
228 | "outputs": []
229 | },
230 | {
231 | "cell_type": "code",
232 | "metadata": {
233 | "id": "FcFF5tuf7R37",
234 | "colab_type": "code",
235 | "colab": {
236 | "base_uri": "https://localhost:8080/",
237 | "height": 243
238 | },
239 | "outputId": "5430dd3c-3bd0-4989-c333-a29ac4136568"
240 | },
241 | "source": [
242 | "print(add)\n",
243 | "print(\"-------------------------------------------------------------\")\n",
244 | "print(sub)\n",
245 | "print(\"-------------------------------------------------------------\")\n",
246 | "print(mul)\n",
247 | "print(\"-------------------------------------------------------------\")\n",
248 | "print(div)\n",
249 | "print(\"-------------------------------------------------------------\")\n",
250 | "print(exp)\n",
251 | "print(\"-------------------------------------------------------------\")\n",
252 | "print(floor)\n",
253 | "print(\"-------------------------------------------------------------\")\n",
254 | "print(mod)"
255 | ],
256 | "execution_count": 12,
257 | "outputs": [
258 | {
259 | "output_type": "stream",
260 | "text": [
261 | "15\n",
262 | "-------------------------------------------------------------\n",
263 | "5\n",
264 | "-------------------------------------------------------------\n",
265 | "50\n",
266 | "-------------------------------------------------------------\n",
267 | "2.0\n",
268 | "-------------------------------------------------------------\n",
269 | "100000\n",
270 | "-------------------------------------------------------------\n",
271 | "2\n",
272 | "-------------------------------------------------------------\n",
273 | "3\n"
274 | ],
275 | "name": "stdout"
276 | }
277 | ]
278 | },
279 | {
280 | "cell_type": "markdown",
281 | "metadata": {
282 | "id": "UuBRpiFt7UKl",
283 | "colab_type": "text"
284 | },
285 | "source": [
286 | "\n",
287 | "\n",
288 | "---\n",
289 | "\n"
290 | ]
291 | }
292 | ]
293 | }
--------------------------------------------------------------------------------
/Strings/String:
--------------------------------------------------------------------------------
1 | # Python Program for
2 | # Creation of String
3 |
4 | # Creating a String
5 | # with single Quotes
6 | String1 = 'Welcome to the Geeks World'
7 | print("String with the use of Single Quotes: ")
8 | print(String1)
9 |
10 | # Creating a String
11 | # with double Quotes
12 | String1 = "I'm a Geek"
13 | print("\nString with the use of Double Quotes: ")
14 | print(String1)
15 |
16 | # Creating a String
17 | # with triple Quotes
18 | String1 = '''I'm a Geek and I live in a world of "Geeks"'''
19 | print("\nString with the use of Triple Quotes: ")
20 | print(String1)
21 |
22 | # Creating String with triple
23 | # Quotes allows multiple lines
24 | String1 = '''Geeks
25 | For
26 | Life'''
27 | print("\nCreating a multiline String: ")
28 | print(String1)
29 |
--------------------------------------------------------------------------------
/Vowel_Count.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyOqQvMYSVHffQwcSDCIXmsN",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "markdown",
31 | "source": [
32 | "# Counting Vowels in a Sentence\n",
33 | "\n",
34 | "\n",
35 | "## Problem\n",
36 | "\n",
37 | "You are tasked with creating a Python script that counts the number of vowels in a given sentence. Your program should prompt the user to enter a sentence, and then output the total count of vowels present in that sentence. The program should treat both uppercase and lowercase vowels as equivalent.\n",
38 | "\n",
39 | "Your task is to write a Python script that accomplishes this, utilizing functions and loops as necessary."
40 | ],
41 | "metadata": {
42 | "id": "oQbsz2YwDc_f"
43 | }
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": 1,
48 | "metadata": {
49 | "colab": {
50 | "base_uri": "https://localhost:8080/"
51 | },
52 | "id": "XAU5DlE0DZpU",
53 | "outputId": "43f94197-a8b0-42c5-fb3b-248340f81b1d"
54 | },
55 | "outputs": [
56 | {
57 | "output_type": "stream",
58 | "name": "stdout",
59 | "text": [
60 | "Enter a sentence: Hello I am a Sales Expert\n",
61 | "Number of vowels: 9\n"
62 | ]
63 | }
64 | ],
65 | "source": [
66 | "def count_vowels(sentence):\n",
67 | " vowels = 'aeiouAEIOU'\n",
68 | " vowel_count = 0\n",
69 | " for char in sentence:\n",
70 | " if char in vowels:\n",
71 | " vowel_count += 1\n",
72 | " return vowel_count\n",
73 | "\n",
74 | "sentence = input(\"Enter a sentence: \")\n",
75 | "print(\"Number of vowels:\", count_vowels(sentence))\n"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "source": [
81 | "This script defines a function count_vowels that takes a sentence as input and returns the count of vowels in it. It iterates over each character in the sentence and checks if it is a vowel. If it is, it increments the count. Finally, it prints out the total count of vowels in the sentence.\n",
82 | "\n",
83 | "\n"
84 | ],
85 | "metadata": {
86 | "id": "euH9m_htD6tG"
87 | }
88 | }
89 | ]
90 | }
--------------------------------------------------------------------------------
/data_load.md:
--------------------------------------------------------------------------------
1 | # Loading a File using Pandas
2 | ## Watch out for different types of file formats!
3 |
4 | 
5 |
6 | [](https://hits.seeyoufarm.com)
7 |
8 | | Function | Description |
9 | | -------- | ------- |
10 | | read_csv | Read a comma-separated values (CSV) file into DataFrame |
11 | | read_table | Read general delimited file into DataFrame |
12 | | read_excel | $420 |
13 | | read_fwf | $420 |
14 | | read_clipboard | $420 |
15 | | read_excel | $420 |
16 |
17 |
--------------------------------------------------------------------------------
/src/2D_Matrix_Multiplication.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | print("Make sure that a should be equal to b * c")
4 | b = int(input("Enter the value of b ===> "))
5 | c = int(input("Enter the value of c ===> "))
6 | a = int(input("Enter the value of a ===> "))
7 |
8 | first = np.arange(a).reshape(b, c)
9 | print(first)
10 |
11 | second = np.arange(a).reshape(b, c)
12 | print(second)
13 |
14 | product = first * second
15 | print(product)
16 |
17 |
--------------------------------------------------------------------------------
/src/Accessing_By_Index.py:
--------------------------------------------------------------------------------
1 | str = "example"
2 | str1 = str[3]
3 | print(str1)
4 |
5 | str2 = "Tanu"[3]
6 | print(str2)
7 |
8 |
--------------------------------------------------------------------------------
/src/Slicing_A_String:
--------------------------------------------------------------------------------
1 | String = "Apple"
2 |
3 | a = String[:3]
4 | print(a)
5 |
6 | b = String[2:5]
7 | print(b)
8 |
9 | c = String[3:]
10 | print(c)
11 |
12 |
13 | d = "Orange"[:3]
14 | print(d)
15 |
16 | e = "Orange"[2:5]
17 | print(e)
18 |
19 | f = "Orange"[3:]
20 | print(f)
21 |
--------------------------------------------------------------------------------
/src/String_Concat_Using_Print.py:
--------------------------------------------------------------------------------
1 | String1 = "Tanu"
2 | String2 = "Nanda"
3 | String3 = "Prabhu"
4 |
5 | print(String1 + " " + String2 + " " + String3)
6 |
--------------------------------------------------------------------------------
/src/Strings.py:
--------------------------------------------------------------------------------
1 | String = " This is a string "
2 | print(String)
3 |
--------------------------------------------------------------------------------
/src/Vending_Machine.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | option = int(input("Enter the option as 1, 2 or 3"))
4 |
5 | if option == 1:
6 | charge = 1.00
7 | elif option == 2:
8 | charge = 1.50
9 | elif option ==3:
10 | charge = 2.00
11 | else:
12 | sys.exit("Invalid option: Try again !!!!!")
13 |
14 | quaters = int(input("Enter the quarters"))
15 | nickels = int(input("Enter the nickles"))
16 | dimes = int(input("Enter the dimes"))
17 | pennies = int(input("Enter the pennis"))
18 |
19 | total = quaters*0.25 + nickels+0.10 + dimes*0.05 + pennies*0.01
20 |
21 | print("You total money is: %f" %(total))
22 |
23 | if total >= charge:
24 | print("You change is: %f" % (total-charge))
25 |
26 | else:
27 | print("Please try again")
28 |
--------------------------------------------------------------------------------
/src/control_Statements.py:
--------------------------------------------------------------------------------
1 | a = input("Enter the value of a: ")
2 | b = input("Enter the value of b: ")
3 | c = input("Enter the value of c: ")
4 |
5 | if a > b > c:
6 | print("a is greater than b and c")
7 | elif b > c > a:
8 | print("b is greater than c and a")
9 | elif a == b == c:
10 | print("a, b, c are all equal")
11 | elif a == b:
12 | print("a and b are equal")
13 | elif b == c:
14 | print("b and c are equal")
15 | elif a == c:
16 | print("a and c are equal")
17 | else:
18 | print("c is greater than a and b")
19 |
20 |
--------------------------------------------------------------------------------
/src/dictionary.py:
--------------------------------------------------------------------------------
1 | name = {1: "Tanu", 2: "Nanda", 3: "Prabhu"}
2 |
3 | print(name[1])
4 | print(name[2])
5 | print(name[3])
6 | print(name)
7 |
8 | # Creating the new Dictinoary from an empty dictionary
9 |
10 | name1 = {}
11 | name1[1] = "Mercedes"
12 | name1[2] = "Benz"
13 |
14 | print(name1)
15 |
16 | # Calculating the length of the dictionary name1 can be done by
17 | length = len(name1)
18 | print(length)
19 |
20 |
21 | # Reassigning the key of the dictionary
22 |
23 | name[2] = "N"
24 | print(name)
25 |
26 | # Removing the key valur pair using a del:
27 |
28 | name2 = {1: "Newton", 2: "Einstein", 3: "Tanu"}
29 | del name2[3]
30 |
31 | print(name2)
32 |
--------------------------------------------------------------------------------
/src/for_loop.py:
--------------------------------------------------------------------------------
1 | list = [1, 2, 3, 4, 5]
2 | for item in list:
3 | print(item)
4 |
--------------------------------------------------------------------------------
/src/functions.py:
--------------------------------------------------------------------------------
1 |
2 | def add(c,d):
3 | e = c + d
4 | return e
5 |
6 |
7 | a = int(input("Enter the value of a:"))
8 | b = int(input("Enter the value of b:"))
9 |
10 | e = add (a, b)
11 | print(e)
12 |
--------------------------------------------------------------------------------
/src/helloWorld.py:
--------------------------------------------------------------------------------
1 | print("Hello World")
2 |
--------------------------------------------------------------------------------
/src/input().py:
--------------------------------------------------------------------------------
1 | firstName = input("Enter your first name")
2 | lastName = input("Enter your last name")
3 | age = input("Enter your age")
4 |
5 | print("Your firstname is: %s, lastname is: %s, and height is: %sl" %(firstName, lastName, age))
6 |
--------------------------------------------------------------------------------
/src/length_of_name.py:
--------------------------------------------------------------------------------
1 | name = input("Enter your name: ")
2 |
3 | length = len(name)
4 |
5 | print("The length of your name is: %s" %(length))
6 |
7 | if length < 4:
8 | print("The name is less than 4 characters")
9 |
10 | elif length < 10 :
11 | print("The name is greater than 4 but less thank 10")
12 | else:
13 | print("The name is very long")
14 |
--------------------------------------------------------------------------------
/src/list.py:
--------------------------------------------------------------------------------
1 | def list():
2 | List = ["Tanu", "Nanda", "Prabhu"]
3 | print(List)
4 |
5 | def byIndex():
6 | List = ["Tanu", "Nanda", "Prabhu"]
7 | Index = List[2]
8 | print(Index)
9 |
10 | def appending():
11 | adder = [1, 2, 3, 4]
12 | adder.append(5)
13 | print(adder)
14 |
15 | def slicing():
16 | slice = [1, 2, 3, 4, 5]
17 | slice1 = slice[:2]
18 | print(slice1)
19 |
20 | def index():
21 | index = [1, 2, 3, 4, 5]
22 | index1 = index.index(3)
23 | print(index1)
24 |
25 | def insert():
26 | insert = ["Tanu", "Nanda"]
27 | insert.insert(2, "Prabhu")
28 | print(insert)
29 |
30 | def remove():
31 | remove = ["Daimler", "Mercedes", "Benz"]
32 | remove.remove("Daimler")
33 | print(remove)
34 |
35 | def pop():
36 | popped = ["BMW", "Mercedes", "Mini"]
37 | pop1 = popped.pop(2)
38 | print(pop1)
39 |
40 | option = int(input("Enter the option such as 1, 2, 3, 4, 5, 6, 7, 8"))
41 |
42 | if option == 1:
43 | list()
44 | elif option == 2:
45 | byIndex()
46 | elif option == 3:
47 | appending()
48 | elif option == 4:
49 | slicing()
50 | elif option == 5:
51 | index()
52 | elif option == 6:
53 | insert()
54 | elif option == 7:
55 | remove()
56 | elif option == 8:
57 | pop()
58 | else:
59 | print("You have entered invalid option !!!!")
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/src/list_functions1.py:
--------------------------------------------------------------------------------
1 | # Passing the entire list as a parameter to the function
2 | list1 = [1, 2, 3, 4, 5, 6]
3 |
4 | def func1(l1):
5 | for item1 in list1:
6 | print(item1)
7 |
8 | func1(list1)
9 |
10 | # Generating the list using a range function
11 |
12 | # range (stop)
13 | list2 = range(5)
14 | print(list2)
15 |
16 | # range (start, stop)
17 | list3 = range(1, 10)
18 | print(list3)
19 |
20 | #range (start, step, stop)
21 | list4 = range(2, 10, 20)
22 | print(list4)
23 |
24 | # range function are innutable, they cannot be modified
25 |
26 | # Using range function in a for loop
27 |
28 | list5 = [1, 3, 5, 7]
29 |
30 | def fun2(l2):
31 | for item3 in range(0, 4):
32 | print(l2[item3])
33 |
34 | fun2(list5)
35 |
36 | # Modifying the list using the range function
37 |
38 | list6 = [1, 2, 3, 4, 5]
39 |
40 | def modify(list):
41 | for item4 in range(0, 5):
42 | list[item4] = list[item4] + 5
43 | print(list[item4])
44 |
45 | modify(list6)
46 |
47 | # Passing multiple lists into the function
48 |
49 | list7 = [1, 2, 3]
50 | list8 = [4, 5, 6]
51 |
52 | def multiple(a, b):
53 | print(a, b)
54 |
55 | multiple(list7, list8 )
56 |
57 | # Iterating through a list of list using a function
58 |
59 | listoflist = [[1, 2, 3], [4, 5, 6]]
60 |
61 | def makeOneList (a):
62 | bothLists = []
63 | for item in a:
64 | for element in item:
65 | bothLists.append(element)
66 | print(bothLists)
67 |
68 | makeOneList(listoflist)
--------------------------------------------------------------------------------
/src/lists_and_functions.py:
--------------------------------------------------------------------------------
1 | # passing a list as a parameter to a function
2 | list = ["Tanu", "Nanda", "Prabhu"]
3 |
4 | def call_list(li):
5 | return li
6 |
7 | print(call_list(list))
8 | print(call_list(list[2]))
9 |
10 | # Accessing an element in a list using a function
11 |
12 | list2 = [1, 2, 3, 4, 5]
13 |
14 | def listing(li1):
15 | return li1
16 |
17 | print(listing(list2[1]))
18 |
19 | # Modifing a list value in a function
20 |
21 | list3 = [4, 3, 2, 1, 0]
22 |
23 | def modify(l1):
24 | return l1[1]+1
25 |
26 | print(modify(list3))
27 |
28 | # Manipulating the list using the functions
29 |
30 | list4 = [1, 1, 3, 8]
31 |
32 | def list_manip(li):
33 | li.remove(3)
34 | li.insert(2,4)
35 | return li
36 |
37 | print(list_manip(list4))
--------------------------------------------------------------------------------
/src/numpy_examples.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | # For arrays of 3 zeros
4 | a = np.zeros(3)
5 | print(a)
6 | print(type(a[0])) # Indicates that a is of float type and the values inside it is of type float
7 |
8 |
9 | # For arrays of 10 zeros
10 | b = np.zeros(10)
11 | print(b)
12 |
13 | # For looking to the shape of the array
14 | print(b.shape)
15 |
16 | # changing the shape of the array from 10 to 1
17 |
18 | b.shape = (10, 1)
19 | print(b)
20 |
21 | # changing the zeros to ones
22 | c = np.ones(5)
23 | print(c)
24 |
25 | # Using line space
26 | d = np.linspace(2, 10, 5)
27 | print(d)
28 |
29 | # another way to create an array
30 | e = np.array([10, 20])
31 | print(e)
32 | print(type(e))
33 |
34 | # also we can add a list in a array
35 | list = [1, 2, 3, 4, 5]
36 | f = np.array([list])
37 | print(f)
38 |
39 | # creating a two dimension array
40 | list2 = [[1, 2, 3, 4],[5, 6, 7,]]
41 |
42 | g = np.array([list2])
43 | print(g)
44 |
45 | # creating a random array using random()
46 |
47 | np.random.seed(0) # if you remove this line then, you can rerun the code and check that the random array is same.
48 |
49 | h = np.random.randint(10, size=6)
50 | print(h)
51 | print(h[-1]) # gets the last element of the array
--------------------------------------------------------------------------------
/src/panda_examples.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import numpy as np
3 |
4 | # There are three datastructures in panda
5 | # 1. Series ==> They are a 1-D Matrix
6 | # 2. DataFrame ==> They are a 2-D Matrix
7 | # 3. Panel ==> They are a 3-D Matrix
8 |
9 |
10 | # Creating a Series Datastructure
11 | a = [1, 2, 3, 4, 5]
12 | series = pd.Series(a)
13 | print(series)
14 |
15 | # Creating the Dataframe Datastructure
16 | b = [['Ashika', 24], ['Tanu', 23], ['Ashwin', 22],['Mohith', 16], ['Sourabh', 10]]
17 | dataframe = pd.DataFrame(b, columns= ['Name', 'Age'], dtype= int)
18 | print(dataframe)
19 |
20 | # Creating the Panel Datastructure
21 | data = {'Item1' : pd.DataFrame(np.random.randn(4, 3)),
22 | 'Item2' : pd.DataFrame(np.random.randn(4, 2))}
23 | p = pd.Panel(data)
24 | print(p.minor_xs(1))
25 |
26 |
--------------------------------------------------------------------------------
/src/tuples.py:
--------------------------------------------------------------------------------
1 | tuple1 = (1, "Hi", True, 8.999)
2 |
3 | print(tuple1)
4 |
5 | tupleEmpty = ()
6 | print(tupleEmpty)
7 |
8 | # Accessing the tuple by Index
9 |
10 | tuple2 = (1, 2, 3, 4, 5)
11 |
12 | print(tuple2[4])
13 | print(tuple2[1])
14 |
15 | # Slicing the tuples
16 |
17 | print(tuple2[1:3])
18 | print(tuple2[:3])
19 |
--------------------------------------------------------------------------------
/src/using_%s_format_operator.py:
--------------------------------------------------------------------------------
1 | name = "Tanu"
2 | lastname = "Nanda_Prabhu"
3 | height = 6.1
4 |
5 | print("The name of the developer is %s %s and his height is %0.1f" %(name, lastname, height))
6 |
--------------------------------------------------------------------------------
/src/variables.py:
--------------------------------------------------------------------------------
1 | variableNamesCannotBeginWithANumber = True
2 | boolean = True
3 | posInt = 2
4 | zero = 0
5 | negFloat = -1
6 | initial = 3
7 | initial = 4
8 | print(initial)
9 |
--------------------------------------------------------------------------------
/src/variables1.py:
--------------------------------------------------------------------------------
1 | """
2 | comments practice:
3 | 1.create a single line comment
4 | 2.create a multiple line comment
5 | """
6 |
7 | # Hi this me
8 |
9 | """
10 | This is me
11 | """
12 |
13 | """
14 | basic mathematical operators practice:
15 | 1.create a variable called add and assign it the sum of two numbers
16 | 2.create a variable called sub and assign it the difference of two numbers
17 | 3.create a variable called mult and assign it the product of two numbers
18 | 4.create a variable called div and assign it the quotient of two numbers
19 | 5.create a variable called power and assign it the value of a number raised to a power
20 | 6.create a variable called mod and assign it the emainder of a quotient
21 | """
22 | add = 5+6
23 | print(add)
24 |
25 | sub = 7-6
26 | print(sub)
27 |
28 | mult = 9*8
29 | print(mult)
30 |
31 | div = 10/2
32 | print(div)
33 |
34 | power = 5**6
35 | print(power)
36 |
37 | mod = 9%4
38 | print(mod)
39 | """
40 | modulo practice:
41 | 1.create a variable called mod1 and assign it the result of 7 % 5
42 | 2.create a variable called mod2 and assign it the result of 16 % 6
43 | 3.create a variable called mod3 and assign it the result of 4 % 3
44 | """
45 | mod1 = 7%5
46 | print(mod1)
47 |
48 | mod2 = 16%6
49 | print(mod2)
50 |
51 | mod3 = 4%3
52 | print(mod3)
53 | """
54 | order of operations practice:
55 | 1.create and assign a variable called ordOp1 the result of 7 + 6 + 9 - 4 * ((9 - 2) ** 2) / 7
56 | 2.create and assign a variable called ordOp2 the result of (6 % 4 * (7 + (7 + 2) * 3)) ** 2
57 | """
58 |
59 | ordOp1 = 7 + 6 + 9 - 4 * ((9 - 2) ** 2) / 7
60 | print(ordOp1)
61 |
62 | ordOp2 = (6 % 4 * (7 + (7 + 2) * 3)) ** 2
63 | print(ordOp2)
64 |
--------------------------------------------------------------------------------