├── Chapter 1 - starting point to become a python warrior ├── 1_Introduction to Basics of Python │ ├── .ipynb_checkpoints │ │ └── 06_Practice Questions Python Beginner-checkpoint.ipynb │ ├── 01_Python Print Statement.ipynb │ ├── 02_Variables and Data Types.ipynb │ ├── 03_Getting Values from User.ipynb │ ├── 04_Type Conversion.ipynb │ ├── 05_First Program in Python.ipynb │ └── 06_Practice Questions Python Beginner.ipynb ├── 2_Operators │ ├── .ipynb_checkpoints │ │ ├── 07_Operators Arithmetic and Relational-checkpoint.ipynb │ │ ├── 08_Operators Bitwise AND-checkpoint.ipynb │ │ ├── 09_Operators Bitwise OR-checkpoint.ipynb │ │ ├── 10_Operator Bitwise XOR-checkpoint.ipynb │ │ ├── 11_Operator Bitwise Left Shift-checkpoint.ipynb │ │ ├── 12_Operator Bitwise Right Shift-checkpoint.ipynb │ │ ├── 13_Boolean and Logical Operators-checkpoint.ipynb │ │ └── 14_Assignment and Compound Operators-checkpoint.ipynb │ ├── 07_Operators Arithmetic and Relational.ipynb │ ├── 08_Operators Bitwise AND.ipynb │ ├── 09_Operators Bitwise OR.ipynb │ ├── 10_Operator Bitwise XOR.ipynb │ ├── 11_Operator Bitwise Left Shift.ipynb │ ├── 12_Operator Bitwise Right Shift.ipynb │ ├── 13_Boolean and Logical Operators.ipynb │ └── 14_Assignment and Compound Operators.ipynb ├── 3_Conditional Statements │ ├── .ipynb_checkpoints │ │ ├── 15_Conditional Statements If and Else-checkpoint.ipynb │ │ ├── 16_Else If and Ternary Statement-checkpoint.ipynb │ │ ├── 17_Nested If and else-checkpoint.ipynb │ │ └── 18_If and Else Practice Questions-checkpoint.ipynb │ ├── 15_Conditional Statements If and Else.ipynb │ ├── 16_Else If and Ternary Statement.ipynb │ ├── 17_Nested If and else.ipynb │ └── 18_If and Else Practice Questions.ipynb ├── 4_While Loop │ ├── .ipynb_checkpoints │ │ ├── 19_While Loop-checkpoint.ipynb │ │ ├── 20_Number Series questions using While Loops-checkpoint.ipynb │ │ ├── 21_Number Series Practice Questions and Answers-checkpoint.ipynb │ │ ├── 22_Break and Continue Statements with While Loops-checkpoint.ipynb │ │ ├── 23_Nested While Loop in Python-checkpoint.ipynb │ │ ├── 24_Pattern Based Question While Loops-checkpoint.ipynb │ │ └── 25_Logic Building Practice Questions and Solutions in Python-checkpoint.ipynb │ ├── 19_While Loop.ipynb │ ├── 20_Number Series questions using While Loops.ipynb │ ├── 21_Number Series Practice Questions and Answers.ipynb │ ├── 22_Break and Continue Statements with While Loops.ipynb │ ├── 23_Nested While Loop in Python.ipynb │ ├── 24_Pattern Based Question While Loops.ipynb │ └── 25_Logic Building Practice Questions and Solutions in Python.ipynb ├── 5_List │ ├── .ipynb_checkpoints │ │ ├── 26_List Basics-checkpoint.ipynb │ │ ├── 27_List Functions-checkpoint.ipynb │ │ ├── 28_List Slicing or Comprehensions-checkpoint.ipynb │ │ └── 29_List Methods-checkpoint.ipynb │ ├── 26_List Basics.ipynb │ ├── 27_List Functions.ipynb │ ├── 28_List Slicing or Comprehensions.ipynb │ └── 29_List Methods.ipynb └── 6_String │ ├── .ipynb_checkpoints │ ├── 30_String Basics-checkpoint.ipynb │ └── 31_String Slicing-checkpoint.ipynb │ ├── 30_String Basics.ipynb │ └── 31_String Slicing.ipynb └── README.md /Chapter 1 - starting point to become a python warrior/1_Introduction to Basics of Python/.ipynb_checkpoints/06_Practice Questions Python Beginner-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ddc51377", 6 | "metadata": {}, 7 | "source": [ 8 | "# Practice Questions\n", 9 | "\n", 10 | "**1 | Write a program to enter 2 numbers from user and print addition, subtraction, multiplication and division of them.**" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "01f34b9a", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "Enter a number: 10\n", 24 | "Enter a number: 20\n", 25 | "Addition = 30\n", 26 | "Subtraction = -10\n", 27 | "Multiplication = 200\n", 28 | "Division = 0.5\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "a = int(input(\"Enter a number: \"))\n", 34 | "b = int(input(\"Enter a number: \"))\n", 35 | "\n", 36 | "c = a + b\n", 37 | "print(\"Addition =\", c)\n", 38 | "\n", 39 | "c = a - b\n", 40 | "print(\"Subtraction =\", c)\n", 41 | "\n", 42 | "c = a * b\n", 43 | "print(\"Multiplication =\", c)\n", 44 | "\n", 45 | "c = a / b\n", 46 | "print(\"Division =\", c)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "id": "5819ca25", 52 | "metadata": {}, 53 | "source": [ 54 | "**2 | Write a program to enter length of a square and print area of it.**" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 5, 60 | "id": "81f94ab4", 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "Enter length of the square side:4\n", 68 | "Area of square= 16\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "x = int(input(\"Enter length of the square side:\"))\n", 74 | "\n", 75 | "area = x * x # x ** 2 \n", 76 | "\n", 77 | "print(\"Area of square=\", area)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "a705ca10", 83 | "metadata": {}, 84 | "source": [ 85 | "**3 | Write a program to enter radius of a circle from user and print area of it.**" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 7, 91 | "id": "90f42901", 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "Enter radius: 2\n", 99 | "Area of circle = 12.56\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "r = float(input(\"Enter radius: \"))\n", 105 | "\n", 106 | "pi = 3.14\n", 107 | "\n", 108 | "area = pi * r * r\n", 109 | "\n", 110 | "print(\"Area of circle =\", area)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "id": "97fba734", 116 | "metadata": {}, 117 | "source": [ 118 | "**4 | Write a program to enter the name from user and greet them.**" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 8, 124 | "id": "3e063e96", 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "name": "stdout", 129 | "output_type": "stream", 130 | "text": [ 131 | "Enter your name: Himanshu\n", 132 | "Hello, How are you? Himanshu\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "name = input(\"Enter your name: \")\n", 138 | "\n", 139 | "print(\"Hello, How are you? \", name)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "id": "74fac927", 145 | "metadata": {}, 146 | "source": [ 147 | "**5 | Write a program to print the following stairs**" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "id": "f758ca36", 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "_\n", 158 | " |_\n", 159 | " |_\n", 160 | " |" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 12, 166 | "id": "2980c676", 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "_\n", 174 | " |_\n", 175 | " |_\n", 176 | " |\n" 177 | ] 178 | } 179 | ], 180 | "source": [ 181 | "print(\"_\\n |_\\n |_\\n |\")" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": null, 187 | "id": "a9f477f0", 188 | "metadata": {}, 189 | "outputs": [], 190 | "source": [] 191 | } 192 | ], 193 | "metadata": { 194 | "kernelspec": { 195 | "display_name": "Python 3 (ipykernel)", 196 | "language": "python", 197 | "name": "python3" 198 | }, 199 | "language_info": { 200 | "codemirror_mode": { 201 | "name": "ipython", 202 | "version": 3 203 | }, 204 | "file_extension": ".py", 205 | "mimetype": "text/x-python", 206 | "name": "python", 207 | "nbconvert_exporter": "python", 208 | "pygments_lexer": "ipython3", 209 | "version": "3.9.12" 210 | } 211 | }, 212 | "nbformat": 4, 213 | "nbformat_minor": 5 214 | } 215 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/1_Introduction to Basics of Python/01_Python Print Statement.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "111b44ac", 6 | "metadata": {}, 7 | "source": [ 8 | "# Print Statement" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "368f7958", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Hello World\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "print(\"Hello World\")" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "id": "a3096f5d", 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "name": "stdout", 37 | "output_type": "stream", 38 | "text": [ 39 | "Hello\n", 40 | "World\n" 41 | ] 42 | } 43 | ], 44 | "source": [ 45 | "print(\"Hello\\nWorld\") # new line character" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 3, 51 | "id": "c0e151ba", 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "Hello\tWorld\n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "print(\"Hello\\tWorld\") # horizontal tab" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 4, 69 | "id": "e2925fe6", 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "name": "stdout", 74 | "output_type": "stream", 75 | "text": [ 76 | "\"Hello\"\n" 77 | ] 78 | } 79 | ], 80 | "source": [ 81 | "print(\"\\\"Hello\\\"\")" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 5, 87 | "id": "2d6eda53", 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "\\Hello\\\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "print(\"\\\\Hello\\\\\")" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "id": "6cd88fd3", 105 | "metadata": {}, 106 | "source": [ 107 | "# Questions\n", 108 | "\n", 109 | "**Print the following output**" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 7, 115 | "id": "2a2c3e4c", 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "Himanshu\n", 123 | "\tMasterDexter\n", 124 | "\t\tIndia\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "print(\"Himanshu\\n\\tMasterDexter\\n\\t\\tIndia\")" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "id": "ca5ad004", 136 | "metadata": {}, 137 | "outputs": [], 138 | "source": [ 139 | "*\n", 140 | "**\n", 141 | "***" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 8, 147 | "id": "81f38efd", 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "*\n", 155 | "**\n", 156 | "***\n" 157 | ] 158 | } 159 | ], 160 | "source": [ 161 | "print(\"*\\n**\\n***\")" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": null, 167 | "id": "43e9f2fc", 168 | "metadata": {}, 169 | "outputs": [], 170 | "source": [ 171 | "--4--*\n", 172 | "*---8---*\n", 173 | "--4--*" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": null, 179 | "id": "1db54109", 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | " *\n", 184 | "* *\n", 185 | " *" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 9, 191 | "id": "e2b43488", 192 | "metadata": {}, 193 | "outputs": [ 194 | { 195 | "name": "stdout", 196 | "output_type": "stream", 197 | "text": [ 198 | " *\n", 199 | "*\t*\n", 200 | " *\n" 201 | ] 202 | } 203 | ], 204 | "source": [ 205 | "print(\" *\\n*\\t*\\n *\")" 206 | ] 207 | } 208 | ], 209 | "metadata": { 210 | "kernelspec": { 211 | "display_name": "Python 3 (ipykernel)", 212 | "language": "python", 213 | "name": "python3" 214 | }, 215 | "language_info": { 216 | "codemirror_mode": { 217 | "name": "ipython", 218 | "version": 3 219 | }, 220 | "file_extension": ".py", 221 | "mimetype": "text/x-python", 222 | "name": "python", 223 | "nbconvert_exporter": "python", 224 | "pygments_lexer": "ipython3", 225 | "version": "3.9.12" 226 | } 227 | }, 228 | "nbformat": 4, 229 | "nbformat_minor": 5 230 | } 231 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/1_Introduction to Basics of Python/02_Variables and Data Types.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a6331ccf", 6 | "metadata": {}, 7 | "source": [ 8 | "# Variables and Data Types" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "996e438d", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "10\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "a = 10\n", 27 | "\n", 28 | "print(a)" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "id": "0c6ed733", 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "10.65\n" 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "b = 10.65\n", 47 | "\n", 48 | "print(b)" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 3, 54 | "id": "ffc1c9b9", 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "India\n" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "c = \"India\"\n", 67 | "\n", 68 | "print(c)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "id": "d3d5e19b", 74 | "metadata": {}, 75 | "source": [ 76 | "# Data Types\n", 77 | "\n", 78 | "#### type function" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 4, 84 | "id": "f4f35f8a", 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "name": "stdout", 89 | "output_type": "stream", 90 | "text": [ 91 | "10\n", 92 | "\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "a = 10\n", 98 | "\n", 99 | "print(a)\n", 100 | "\n", 101 | "print(type(a))" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 5, 107 | "id": "62b76e6f", 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "10.65\n", 115 | "\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "b = 10.65\n", 121 | "\n", 122 | "print(b)\n", 123 | "\n", 124 | "print(type(b))" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 6, 130 | "id": "6255c004", 131 | "metadata": {}, 132 | "outputs": [ 133 | { 134 | "name": "stdout", 135 | "output_type": "stream", 136 | "text": [ 137 | "India\n", 138 | "\n" 139 | ] 140 | } 141 | ], 142 | "source": [ 143 | "c = \"India\"\n", 144 | "\n", 145 | "print(c)\n", 146 | "\n", 147 | "print(type(c))" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 7, 153 | "id": "75a61520", 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "15\n", 161 | "10\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "a = 10\n", 167 | "\n", 168 | "print(a + 5)\n", 169 | "\n", 170 | "print(a)" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 8, 176 | "id": "942f3876", 177 | "metadata": {}, 178 | "outputs": [ 179 | { 180 | "name": "stdout", 181 | "output_type": "stream", 182 | "text": [ 183 | "15\n" 184 | ] 185 | } 186 | ], 187 | "source": [ 188 | "a = 10\n", 189 | "\n", 190 | "a = a + 5\n", 191 | "\n", 192 | "print(a)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "id": "bbe65df8", 199 | "metadata": {}, 200 | "outputs": [], 201 | "source": [] 202 | } 203 | ], 204 | "metadata": { 205 | "kernelspec": { 206 | "display_name": "Python 3 (ipykernel)", 207 | "language": "python", 208 | "name": "python3" 209 | }, 210 | "language_info": { 211 | "codemirror_mode": { 212 | "name": "ipython", 213 | "version": 3 214 | }, 215 | "file_extension": ".py", 216 | "mimetype": "text/x-python", 217 | "name": "python", 218 | "nbconvert_exporter": "python", 219 | "pygments_lexer": "ipython3", 220 | "version": "3.9.12" 221 | } 222 | }, 223 | "nbformat": 4, 224 | "nbformat_minor": 5 225 | } 226 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/1_Introduction to Basics of Python/03_Getting Values from User.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "4536963a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Getting Values from User" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "defd92b5", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "10\n", 22 | "10\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "a = input()\n", 28 | "\n", 29 | "print(a)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "a6ea21fb", 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "Enter a Number: 100\n", 43 | "100\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "b = input(\"Enter a Number: \")\n", 49 | "\n", 50 | "print(b)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 3, 56 | "id": "c28a7082", 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "Enter Your Name: Himanshu\n", 64 | "Hello! Himanshu\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "x = input(\"Enter Your Name: \")\n", 70 | "\n", 71 | "print(\"Hello!\", x)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 4, 77 | "id": "dfa716e2", 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "name": "stdout", 82 | "output_type": "stream", 83 | "text": [ 84 | "Enter Your Password: 12345\n", 85 | "Your Password is : 12345\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "password = input(\"Enter Your Password: \")\n", 91 | "\n", 92 | "print(\"Your Password is : \", password)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "id": "8d0d6334", 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [] 102 | } 103 | ], 104 | "metadata": { 105 | "kernelspec": { 106 | "display_name": "Python 3 (ipykernel)", 107 | "language": "python", 108 | "name": "python3" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": { 112 | "name": "ipython", 113 | "version": 3 114 | }, 115 | "file_extension": ".py", 116 | "mimetype": "text/x-python", 117 | "name": "python", 118 | "nbconvert_exporter": "python", 119 | "pygments_lexer": "ipython3", 120 | "version": "3.9.12" 121 | } 122 | }, 123 | "nbformat": 4, 124 | "nbformat_minor": 5 125 | } 126 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/1_Introduction to Basics of Python/04_Type Conversion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "505fc528", 6 | "metadata": {}, 7 | "source": [ 8 | "# Type Conversion\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "8fc0915d", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "ename": "TypeError", 19 | "evalue": "unsupported operand type(s) for +: 'int' and 'str'", 20 | "output_type": "error", 21 | "traceback": [ 22 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 23 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 24 | "Input \u001b[1;32mIn [1]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;241;43m10\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mA\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n", 25 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'" 26 | ] 27 | } 28 | ], 29 | "source": [ 30 | "10 + \"A\"" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "id": "f0e39b61", 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "\n", 44 | "\n" 45 | ] 46 | }, 47 | { 48 | "ename": "TypeError", 49 | "evalue": "unsupported operand type(s) for +: 'int' and 'str'", 50 | "output_type": "error", 51 | "traceback": [ 52 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 53 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 54 | "Input \u001b[1;32mIn [2]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mtype\u001b[39m(a))\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mtype\u001b[39m(b))\n\u001b[1;32m----> 8\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43ma\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mb\u001b[49m)\n", 55 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'" 56 | ] 57 | } 58 | ], 59 | "source": [ 60 | "a = 10\n", 61 | "\n", 62 | "b = \"20\"\n", 63 | "\n", 64 | "print(type(a))\n", 65 | "print(type(b))\n", 66 | "\n", 67 | "print(a + b)" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 3, 73 | "id": "b773726d", 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "name": "stdout", 78 | "output_type": "stream", 79 | "text": [ 80 | "\n", 81 | "\n", 82 | "30\n", 83 | "\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "a = 10\n", 89 | "\n", 90 | "b = \"20\"\n", 91 | "\n", 92 | "print(type(a))\n", 93 | "print(type(b))\n", 94 | "\n", 95 | "c = int(b)\n", 96 | "\n", 97 | "print(a + c)\n", 98 | "\n", 99 | "print(type(c))" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 4, 105 | "id": "4b85f5b2", 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "ename": "ValueError", 110 | "evalue": "invalid literal for int() with base 10: 'A'", 111 | "output_type": "error", 112 | "traceback": [ 113 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 114 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 115 | "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m10\u001b[39m\n\u001b[0;32m 3\u001b[0m b \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mA\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mb\u001b[49m\u001b[43m)\u001b[49m)\n", 116 | "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: 'A'" 117 | ] 118 | } 119 | ], 120 | "source": [ 121 | "a = 10\n", 122 | "\n", 123 | "b = \"A\"\n", 124 | "\n", 125 | "print(int(b))" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 5, 131 | "id": "bc000d1c", 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "name": "stdout", 136 | "output_type": "stream", 137 | "text": [ 138 | "\n", 139 | "\n", 140 | "\n", 141 | "\n", 142 | "100200\n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "a = 100\n", 148 | "\n", 149 | "b = 200\n", 150 | "\n", 151 | "print(type(a))\n", 152 | "print(type(b))\n", 153 | "\n", 154 | "c = str(a)\n", 155 | "d = str(b)\n", 156 | "\n", 157 | "print(type(c))\n", 158 | "print(type(d))\n", 159 | "\n", 160 | "print(c + d)" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 6, 166 | "id": "712b3f87", 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "data": { 171 | "text/plain": [ 172 | "'AB'" 173 | ] 174 | }, 175 | "execution_count": 6, 176 | "metadata": {}, 177 | "output_type": "execute_result" 178 | } 179 | ], 180 | "source": [ 181 | "\"A\" + \"B\"" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 7, 187 | "id": "7c2c41bf", 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "data": { 192 | "text/plain": [ 193 | "'India is the Best'" 194 | ] 195 | }, 196 | "execution_count": 7, 197 | "metadata": {}, 198 | "output_type": "execute_result" 199 | } 200 | ], 201 | "source": [ 202 | "\"India\" + \" is the \" + \"Best\"" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 9, 208 | "id": "a9f64522", 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "name": "stdout", 213 | "output_type": "stream", 214 | "text": [ 215 | "10.65\n", 216 | "\n", 217 | "\n", 218 | "10\n" 219 | ] 220 | } 221 | ], 222 | "source": [ 223 | "a = 10.65\n", 224 | "\n", 225 | "print(a)\n", 226 | "print(type(a))\n", 227 | "\n", 228 | "b = int(a)\n", 229 | "\n", 230 | "print(type(b))\n", 231 | "print(b)" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": null, 237 | "id": "f1dccafe", 238 | "metadata": {}, 239 | "outputs": [], 240 | "source": [] 241 | } 242 | ], 243 | "metadata": { 244 | "kernelspec": { 245 | "display_name": "Python 3 (ipykernel)", 246 | "language": "python", 247 | "name": "python3" 248 | }, 249 | "language_info": { 250 | "codemirror_mode": { 251 | "name": "ipython", 252 | "version": 3 253 | }, 254 | "file_extension": ".py", 255 | "mimetype": "text/x-python", 256 | "name": "python", 257 | "nbconvert_exporter": "python", 258 | "pygments_lexer": "ipython3", 259 | "version": "3.9.12" 260 | } 261 | }, 262 | "nbformat": 4, 263 | "nbformat_minor": 5 264 | } 265 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/1_Introduction to Basics of Python/05_First Program in Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "8205f44d", 6 | "metadata": {}, 7 | "source": [ 8 | "# First Program in Python\n", 9 | "\n", 10 | "**Write a program to enter 2 numbers from user and print addition of them**" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "f67bb325", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "Enter 1st Number: 10\n", 24 | "Enter 2nd Number: 20\n", 25 | "1020\n" 26 | ] 27 | } 28 | ], 29 | "source": [ 30 | "a = input(\"Enter 1st Number: \")\n", 31 | "b = input(\"Enter 2nd Number: \")\n", 32 | "\n", 33 | "c = a + b\n", 34 | "\n", 35 | "print(c)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 2, 41 | "id": "92d08572", 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "name": "stdout", 46 | "output_type": "stream", 47 | "text": [ 48 | "\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "print(type(a))" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 3, 59 | "id": "c0a80669", 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "Enter 1st Number: 10\n", 67 | "Enter 2nd Number: 20\n", 68 | "30\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "a = int(input(\"Enter 1st Number: \"))\n", 74 | "b = int(input(\"Enter 2nd Number: \"))\n", 75 | "\n", 76 | "c = a + b\n", 77 | "\n", 78 | "print(c)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 4, 84 | "id": "5fc10126", 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "name": "stdout", 89 | "output_type": "stream", 90 | "text": [ 91 | "Enter 1st Number: 10\n", 92 | "Enter 2nd Number: 20\n", 93 | "Addition = 30\n" 94 | ] 95 | } 96 | ], 97 | "source": [ 98 | "a = int(input(\"Enter 1st Number: \"))\n", 99 | "b = int(input(\"Enter 2nd Number: \"))\n", 100 | "\n", 101 | "c = a + b\n", 102 | "\n", 103 | "print(\"Addition =\",c)" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "id": "e09fb5fe", 109 | "metadata": {}, 110 | "source": [ 111 | "# Questions\n", 112 | "\n", 113 | "**Write a program to enter 2 numbers from user and print addition, subtraction, multiplication and division.**" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "id": "cad2ce42", 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [] 123 | } 124 | ], 125 | "metadata": { 126 | "kernelspec": { 127 | "display_name": "Python 3 (ipykernel)", 128 | "language": "python", 129 | "name": "python3" 130 | }, 131 | "language_info": { 132 | "codemirror_mode": { 133 | "name": "ipython", 134 | "version": 3 135 | }, 136 | "file_extension": ".py", 137 | "mimetype": "text/x-python", 138 | "name": "python", 139 | "nbconvert_exporter": "python", 140 | "pygments_lexer": "ipython3", 141 | "version": "3.9.12" 142 | } 143 | }, 144 | "nbformat": 4, 145 | "nbformat_minor": 5 146 | } 147 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/1_Introduction to Basics of Python/06_Practice Questions Python Beginner.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ddc51377", 6 | "metadata": {}, 7 | "source": [ 8 | "# Practice Questions\n", 9 | "\n", 10 | "**1 | Write a program to enter 2 numbers from user and print addition, subtraction, multiplication and division of them.**" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "01f34b9a", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "Enter a number: 10\n", 24 | "Enter a number: 20\n", 25 | "Addition = 30\n", 26 | "Subtraction = -10\n", 27 | "Multiplication = 200\n", 28 | "Division = 0.5\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "a = int(input(\"Enter a number: \"))\n", 34 | "b = int(input(\"Enter a number: \"))\n", 35 | "\n", 36 | "c = a + b\n", 37 | "print(\"Addition =\", c)\n", 38 | "\n", 39 | "c = a - b\n", 40 | "print(\"Subtraction =\", c)\n", 41 | "\n", 42 | "c = a * b\n", 43 | "print(\"Multiplication =\", c)\n", 44 | "\n", 45 | "c = a / b\n", 46 | "print(\"Division =\", c)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "id": "5819ca25", 52 | "metadata": {}, 53 | "source": [ 54 | "**2 | Write a program to enter length of a square and print area of it.**" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 5, 60 | "id": "81f94ab4", 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "Enter length of the square side:4\n", 68 | "Area of square= 16\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "x = int(input(\"Enter length of the square side:\"))\n", 74 | "\n", 75 | "area = x * x # x ** 2 \n", 76 | "\n", 77 | "print(\"Area of square=\", area)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "a705ca10", 83 | "metadata": {}, 84 | "source": [ 85 | "**3 | Write a program to enter radius of a circle from user and print area of it.**" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 7, 91 | "id": "90f42901", 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "Enter radius: 2\n", 99 | "Area of circle = 12.56\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "r = float(input(\"Enter radius: \"))\n", 105 | "\n", 106 | "pi = 3.14\n", 107 | "\n", 108 | "area = pi * r * r\n", 109 | "\n", 110 | "print(\"Area of circle =\", area)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "id": "97fba734", 116 | "metadata": {}, 117 | "source": [ 118 | "**4 | Write a program to enter the name from user and greet them.**" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 8, 124 | "id": "3e063e96", 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "name": "stdout", 129 | "output_type": "stream", 130 | "text": [ 131 | "Enter your name: Himanshu\n", 132 | "Hello, How are you? Himanshu\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "name = input(\"Enter your name: \")\n", 138 | "\n", 139 | "print(\"Hello, How are you? \", name)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "id": "74fac927", 145 | "metadata": {}, 146 | "source": [ 147 | "**5 | Write a program to print the following stairs**" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "id": "f758ca36", 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "_\n", 158 | " |_\n", 159 | " |_\n", 160 | " |" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 12, 166 | "id": "2980c676", 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "_\n", 174 | " |_\n", 175 | " |_\n", 176 | " |\n" 177 | ] 178 | } 179 | ], 180 | "source": [ 181 | "print(\"_\\n |_\\n |_\\n |\")" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": null, 187 | "id": "a9f477f0", 188 | "metadata": {}, 189 | "outputs": [], 190 | "source": [] 191 | } 192 | ], 193 | "metadata": { 194 | "kernelspec": { 195 | "display_name": "Python 3 (ipykernel)", 196 | "language": "python", 197 | "name": "python3" 198 | }, 199 | "language_info": { 200 | "codemirror_mode": { 201 | "name": "ipython", 202 | "version": 3 203 | }, 204 | "file_extension": ".py", 205 | "mimetype": "text/x-python", 206 | "name": "python", 207 | "nbconvert_exporter": "python", 208 | "pygments_lexer": "ipython3", 209 | "version": "3.9.12" 210 | } 211 | }, 212 | "nbformat": 4, 213 | "nbformat_minor": 5 214 | } 215 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/.ipynb_checkpoints/08_Operators Bitwise AND-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "32cdbfdb", 6 | "metadata": {}, 7 | "source": [ 8 | "# Bitwise Operators" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "id": "26419392", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "& -> bitwise and\n", 19 | "| -> bitwise or\n", 20 | "^ -> bitwise xor\n", 21 | "<< -> bitwise leftshift\n", 22 | ">> -> bitwise rightshift" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "id": "6b49f93c", 28 | "metadata": {}, 29 | "source": [ 30 | "# & -> bitwise and\n" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "id": "e3150dd8", 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "0\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "print(8 & 2)" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "id": "8d46ed98", 54 | "metadata": {}, 55 | "source": [ 56 | "# Binary Numbers" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "id": "887e7d6f", 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "1024 512 256 128 64 32 16 8 4 2 1\n", 67 | " 1 0 0 0\n", 68 | " 1 0\n", 69 | " 0 0 0 0\n", 70 | " 1 0 1 1\n", 71 | " 1 1\n", 72 | " 1 1 0 1 1\n", 73 | " 1 1 0 0 1" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "id": "8ab83c3e", 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "truth tables\n", 84 | "& \n", 85 | "0 & 0 -> 0 \n", 86 | "0 & 1 -> 0\n", 87 | "1 & 0 -> 0\n", 88 | "1 & 1 -> 1" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "id": "0fc892ff", 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "1000\n", 99 | "0010 &\n", 100 | "0000" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 3, 106 | "id": "2ebbe530", 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "3\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "print(11 & 3)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "id": "e2c33fba", 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [ 128 | "1011\n", 129 | "0011 &\n", 130 | "0011" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 4, 136 | "id": "f14c2e3a", 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "data": { 141 | "text/plain": [ 142 | "11" 143 | ] 144 | }, 145 | "execution_count": 4, 146 | "metadata": {}, 147 | "output_type": "execute_result" 148 | } 149 | ], 150 | "source": [ 151 | "27 & 11" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "id": "5bb24d18", 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [ 161 | "11011\n", 162 | "01011 &\n", 163 | "01011" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 5, 169 | "id": "9f1fdb6b", 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "data": { 174 | "text/plain": [ 175 | "25" 176 | ] 177 | }, 178 | "execution_count": 5, 179 | "metadata": {}, 180 | "output_type": "execute_result" 181 | } 182 | ], 183 | "source": [ 184 | "31 & 25" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": null, 190 | "id": "877d5a15", 191 | "metadata": {}, 192 | "outputs": [], 193 | "source": [ 194 | "11111\n", 195 | "11001 &\n", 196 | "11001" 197 | ] 198 | } 199 | ], 200 | "metadata": { 201 | "kernelspec": { 202 | "display_name": "Python 3 (ipykernel)", 203 | "language": "python", 204 | "name": "python3" 205 | }, 206 | "language_info": { 207 | "codemirror_mode": { 208 | "name": "ipython", 209 | "version": 3 210 | }, 211 | "file_extension": ".py", 212 | "mimetype": "text/x-python", 213 | "name": "python", 214 | "nbconvert_exporter": "python", 215 | "pygments_lexer": "ipython3", 216 | "version": "3.9.12" 217 | } 218 | }, 219 | "nbformat": 4, 220 | "nbformat_minor": 5 221 | } 222 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/.ipynb_checkpoints/09_Operators Bitwise OR-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e421d0b6", 6 | "metadata": {}, 7 | "source": [ 8 | "# Bitwise OR" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "id": "b1e9270b", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "& -> bitwise and\n", 19 | "| -> bitwise or\n", 20 | "^ -> bitwise xor\n", 21 | "<< -> bitwise leftshift\n", 22 | ">> -> bitwise rightshift" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 1, 28 | "id": "892f9fea", 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "10\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "print(10 | 8)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "id": "7c530d50", 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "1024 512 256 128 64 32 16 8 4 2 1\n", 51 | " 1 0 1 0\n", 52 | " 1 0 0 0\n", 53 | " 1 0 1 1 0\n", 54 | " 1 0 1 1 1" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "id": "d345f350", 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "truth table\n", 65 | "|\n", 66 | "0 | 0 -> 0\n", 67 | "0 | 1 -> 1\n", 68 | "1 | 0 -> 1\n", 69 | "1 | 1 -> 1" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "id": "366eec9c", 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "1010\n", 80 | "1000 |\n", 81 | "1010" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 2, 87 | "id": "d7cc28dd", 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "23\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "print(17 | 22)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "id": "c24ce992", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "10001\n", 110 | "10110 |\n", 111 | "10111 ---> 23" 112 | ] 113 | } 114 | ], 115 | "metadata": { 116 | "kernelspec": { 117 | "display_name": "Python 3 (ipykernel)", 118 | "language": "python", 119 | "name": "python3" 120 | }, 121 | "language_info": { 122 | "codemirror_mode": { 123 | "name": "ipython", 124 | "version": 3 125 | }, 126 | "file_extension": ".py", 127 | "mimetype": "text/x-python", 128 | "name": "python", 129 | "nbconvert_exporter": "python", 130 | "pygments_lexer": "ipython3", 131 | "version": "3.9.12" 132 | } 133 | }, 134 | "nbformat": 4, 135 | "nbformat_minor": 5 136 | } 137 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/.ipynb_checkpoints/10_Operator Bitwise XOR-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "af3d90e1", 6 | "metadata": {}, 7 | "source": [ 8 | "# Operator Bitwise XOR\n", 9 | "\n", 10 | "Watch the video in 1.5x speed to better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "6b731f3a", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "5\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "print(12 ^ 9)" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "id": "658deead", 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "1024 512 256 128 64 32 16 8 4 2 1\n", 39 | " 1 1 0 0\n", 40 | " 1 0 0 1\n", 41 | " 0 1 0 1\n", 42 | " 1 1 0 1 1\n", 43 | " 0 1 1 1 0" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "id": "6e2c0517", 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "truth table\n", 54 | "^\n", 55 | "0 ^ 0 -> 0\n", 56 | "0 ^ 1 -> 1\n", 57 | "1 ^ 0 -> 1\n", 58 | "1 ^ 1 -> 0" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "id": "eac14af2", 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "1100\n", 69 | "1001 ^\n", 70 | "0101" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 2, 76 | "id": "a7091268", 77 | "metadata": {}, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "14\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "print(21 ^ 27)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "id": "04c9b93c", 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "10101\n", 99 | "11011 ^\n", 100 | "01110" 101 | ] 102 | } 103 | ], 104 | "metadata": { 105 | "kernelspec": { 106 | "display_name": "Python 3 (ipykernel)", 107 | "language": "python", 108 | "name": "python3" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": { 112 | "name": "ipython", 113 | "version": 3 114 | }, 115 | "file_extension": ".py", 116 | "mimetype": "text/x-python", 117 | "name": "python", 118 | "nbconvert_exporter": "python", 119 | "pygments_lexer": "ipython3", 120 | "version": "3.9.12" 121 | } 122 | }, 123 | "nbformat": 4, 124 | "nbformat_minor": 5 125 | } 126 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/.ipynb_checkpoints/11_Operator Bitwise Left Shift-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/.ipynb_checkpoints/12_Operator Bitwise Right Shift-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/.ipynb_checkpoints/13_Boolean and Logical Operators-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "2b42139a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Boolean and Logical Operators\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "601149c9", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "# boolean operators\n", 21 | "\n", 22 | "True\n", 23 | "\n", 24 | "False\n" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "id": "322a34f8", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "# logical operators\n", 35 | "\n", 36 | "not\n", 37 | "and\n", 38 | "or" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 1, 44 | "id": "7ab82743", 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "False\n" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "print(not True)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 2, 62 | "id": "e70fddaf", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "True\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "print(not False)" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 3, 80 | "id": "266908ee", 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "ename": "SyntaxError", 85 | "evalue": "invalid syntax (941600843.py, line 1)", 86 | "output_type": "error", 87 | "traceback": [ 88 | "\u001b[1;36m Input \u001b[1;32mIn [3]\u001b[1;36m\u001b[0m\n\u001b[1;33m print(False not)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "print(False not)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "id": "979c50d5", 100 | "metadata": {}, 101 | "outputs": [], 102 | "source": [ 103 | "# truth table for and\n", 104 | "0 = False, 1 = True\n", 105 | "\n", 106 | "False and False = False\n", 107 | "False and True = False\n", 108 | "True and False = False\n", 109 | "True and True = True" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 4, 115 | "id": "936c2a02", 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "False\n" 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "print(False and True)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 5, 133 | "id": "ec650747", 134 | "metadata": {}, 135 | "outputs": [ 136 | { 137 | "name": "stdout", 138 | "output_type": "stream", 139 | "text": [ 140 | "False\n" 141 | ] 142 | } 143 | ], 144 | "source": [ 145 | "print(False and True and False and True)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "id": "25af6191", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "# truth table for or\n", 156 | "0 = False, 1 = True\n", 157 | "\n", 158 | "False or False = False\n", 159 | "False or True = True\n", 160 | "True or False = True\n", 161 | "True or True = True" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 6, 167 | "id": "e45a60b7", 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "name": "stdout", 172 | "output_type": "stream", 173 | "text": [ 174 | "True\n" 175 | ] 176 | } 177 | ], 178 | "source": [ 179 | "print(True or False or True or False or False)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "id": "1f87798b", 185 | "metadata": {}, 186 | "source": [ 187 | "## Combine all the logical operators in a Question" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "id": "6ab9fe23", 194 | "metadata": {}, 195 | "outputs": [], 196 | "source": [ 197 | "# priority\n", 198 | "\n", 199 | "1. not\n", 200 | "2. and\n", 201 | "3. or" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 7, 207 | "id": "f576c7a4", 208 | "metadata": {}, 209 | "outputs": [ 210 | { 211 | "name": "stdout", 212 | "output_type": "stream", 213 | "text": [ 214 | "True\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "print(False and not True or False and not False or True and not False and True)\n", 220 | "# False True True\n", 221 | "# False False True\n", 222 | "# True\n", 223 | "# True" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": null, 229 | "id": "594098c2", 230 | "metadata": {}, 231 | "outputs": [], 232 | "source": [] 233 | } 234 | ], 235 | "metadata": { 236 | "kernelspec": { 237 | "display_name": "Python 3 (ipykernel)", 238 | "language": "python", 239 | "name": "python3" 240 | }, 241 | "language_info": { 242 | "codemirror_mode": { 243 | "name": "ipython", 244 | "version": 3 245 | }, 246 | "file_extension": ".py", 247 | "mimetype": "text/x-python", 248 | "name": "python", 249 | "nbconvert_exporter": "python", 250 | "pygments_lexer": "ipython3", 251 | "version": "3.9.12" 252 | } 253 | }, 254 | "nbformat": 4, 255 | "nbformat_minor": 5 256 | } 257 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/.ipynb_checkpoints/14_Assignment and Compound Operators-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9834988f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Assignment and Compound Operators\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "d47edd78", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "# Assignment\n", 21 | "=" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "id": "304a393c", 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "10\n", 35 | "20\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "a = 10\n", 41 | "\n", 42 | "print(a)\n", 43 | "\n", 44 | "a = 20\n", 45 | "\n", 46 | "print(a)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "id": "f6e9aa67", 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "# compound operators\n", 57 | "+=, -=, *= , /=, **=, //=, %=" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 2, 63 | "id": "4df58fbb", 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "15\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "a = 10\n", 76 | "\n", 77 | "a += 5 # a = a + 5\n", 78 | "\n", 79 | "print(a)" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 3, 85 | "id": "a00f6018", 86 | "metadata": {}, 87 | "outputs": [ 88 | { 89 | "name": "stdout", 90 | "output_type": "stream", 91 | "text": [ 92 | "8\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "a = 10\n", 98 | "\n", 99 | "a -= 2 # a = a - 2\n", 100 | "\n", 101 | "print(a)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 4, 107 | "id": "0ebc52ee", 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "10.0\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "b = 20\n", 120 | "\n", 121 | "b /= 2 # b = b / 2\n", 122 | "\n", 123 | "print(b)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 5, 129 | "id": "7fd0dde4", 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "name": "stdout", 134 | "output_type": "stream", 135 | "text": [ 136 | "27\n" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "c = 3\n", 142 | "\n", 143 | "c **= 3 # c = c ** 3\n", 144 | "\n", 145 | "print(c)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 6, 151 | "id": "33a064a7", 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "2\n" 159 | ] 160 | } 161 | ], 162 | "source": [ 163 | "d = 10\n", 164 | "\n", 165 | "d %= 4 # d = d % 4\n", 166 | "\n", 167 | "print(d)" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "id": "91c8e9f1", 174 | "metadata": {}, 175 | "outputs": [], 176 | "source": [] 177 | } 178 | ], 179 | "metadata": { 180 | "kernelspec": { 181 | "display_name": "Python 3 (ipykernel)", 182 | "language": "python", 183 | "name": "python3" 184 | }, 185 | "language_info": { 186 | "codemirror_mode": { 187 | "name": "ipython", 188 | "version": 3 189 | }, 190 | "file_extension": ".py", 191 | "mimetype": "text/x-python", 192 | "name": "python", 193 | "nbconvert_exporter": "python", 194 | "pygments_lexer": "ipython3", 195 | "version": "3.9.12" 196 | } 197 | }, 198 | "nbformat": 4, 199 | "nbformat_minor": 5 200 | } 201 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/07_Operators Arithmetic and Relational.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "bc178694", 6 | "metadata": {}, 7 | "source": [ 8 | "# Arithmetic Operators" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "id": "2c2ab36c", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "+, -, *, /, //, **, % " 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 1, 24 | "id": "9de1744c", 25 | "metadata": {}, 26 | "outputs": [ 27 | { 28 | "data": { 29 | "text/plain": [ 30 | "30" 31 | ] 32 | }, 33 | "execution_count": 1, 34 | "metadata": {}, 35 | "output_type": "execute_result" 36 | } 37 | ], 38 | "source": [ 39 | "10 + 20" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 2, 45 | "id": "26f516cf", 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "6" 52 | ] 53 | }, 54 | "execution_count": 2, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "12 - 6" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 3, 66 | "id": "c07c4b7c", 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "data": { 71 | "text/plain": [ 72 | "49" 73 | ] 74 | }, 75 | "execution_count": 3, 76 | "metadata": {}, 77 | "output_type": "execute_result" 78 | } 79 | ], 80 | "source": [ 81 | "7 * 7" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 4, 87 | "id": "88211d51", 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "data": { 92 | "text/plain": [ 93 | "3.0" 94 | ] 95 | }, 96 | "execution_count": 4, 97 | "metadata": {}, 98 | "output_type": "execute_result" 99 | } 100 | ], 101 | "source": [ 102 | "6 / 2" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 5, 108 | "id": "784a6344", 109 | "metadata": {}, 110 | "outputs": [ 111 | { 112 | "data": { 113 | "text/plain": [ 114 | "1" 115 | ] 116 | }, 117 | "execution_count": 5, 118 | "metadata": {}, 119 | "output_type": "execute_result" 120 | } 121 | ], 122 | "source": [ 123 | "# modulo %\n", 124 | "\n", 125 | "7 % 2 # reminder" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 6, 131 | "id": "0f601717", 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "1" 138 | ] 139 | }, 140 | "execution_count": 6, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "10 % 3" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 7, 152 | "id": "6c2f7d5f", 153 | "metadata": {}, 154 | "outputs": [ 155 | { 156 | "data": { 157 | "text/plain": [ 158 | "3" 159 | ] 160 | }, 161 | "execution_count": 7, 162 | "metadata": {}, 163 | "output_type": "execute_result" 164 | } 165 | ], 166 | "source": [ 167 | "15 % 6" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 8, 173 | "id": "b23281ea", 174 | "metadata": {}, 175 | "outputs": [ 176 | { 177 | "data": { 178 | "text/plain": [ 179 | "3" 180 | ] 181 | }, 182 | "execution_count": 8, 183 | "metadata": {}, 184 | "output_type": "execute_result" 185 | } 186 | ], 187 | "source": [ 188 | "# floor division\n", 189 | "\n", 190 | "7 // 2 # 3.5 " 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 9, 196 | "id": "b4f7593d", 197 | "metadata": {}, 198 | "outputs": [ 199 | { 200 | "data": { 201 | "text/plain": [ 202 | "1" 203 | ] 204 | }, 205 | "execution_count": 9, 206 | "metadata": {}, 207 | "output_type": "execute_result" 208 | } 209 | ], 210 | "source": [ 211 | "14 // 8 # 1." 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 10, 217 | "id": "95dc23ae", 218 | "metadata": {}, 219 | "outputs": [ 220 | { 221 | "data": { 222 | "text/plain": [ 223 | "8" 224 | ] 225 | }, 226 | "execution_count": 10, 227 | "metadata": {}, 228 | "output_type": "execute_result" 229 | } 230 | ], 231 | "source": [ 232 | "# exponents\n", 233 | "\n", 234 | "2 ** 3 # 2 to the power 3" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 11, 240 | "id": "d93ef3aa", 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "data": { 245 | "text/plain": [ 246 | "343" 247 | ] 248 | }, 249 | "execution_count": 11, 250 | "metadata": {}, 251 | "output_type": "execute_result" 252 | } 253 | ], 254 | "source": [ 255 | "7 ** 3" 256 | ] 257 | }, 258 | { 259 | "cell_type": "markdown", 260 | "id": "7afd6bfd", 261 | "metadata": {}, 262 | "source": [ 263 | "# Relational Operators" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": null, 269 | "id": "bfd49b0a", 270 | "metadata": {}, 271 | "outputs": [], 272 | "source": [ 273 | "> , < , >= , <=, ==, != " 274 | ] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "execution_count": 12, 279 | "id": "97d85bd4", 280 | "metadata": {}, 281 | "outputs": [ 282 | { 283 | "data": { 284 | "text/plain": [ 285 | "True" 286 | ] 287 | }, 288 | "execution_count": 12, 289 | "metadata": {}, 290 | "output_type": "execute_result" 291 | } 292 | ], 293 | "source": [ 294 | "10 > 5" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": 13, 300 | "id": "99b90cc3", 301 | "metadata": {}, 302 | "outputs": [ 303 | { 304 | "data": { 305 | "text/plain": [ 306 | "False" 307 | ] 308 | }, 309 | "execution_count": 13, 310 | "metadata": {}, 311 | "output_type": "execute_result" 312 | } 313 | ], 314 | "source": [ 315 | "11 < 5" 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 14, 321 | "id": "92cf7305", 322 | "metadata": {}, 323 | "outputs": [ 324 | { 325 | "data": { 326 | "text/plain": [ 327 | "True" 328 | ] 329 | }, 330 | "execution_count": 14, 331 | "metadata": {}, 332 | "output_type": "execute_result" 333 | } 334 | ], 335 | "source": [ 336 | "10 >= 10" 337 | ] 338 | }, 339 | { 340 | "cell_type": "code", 341 | "execution_count": 15, 342 | "id": "065fae21", 343 | "metadata": {}, 344 | "outputs": [ 345 | { 346 | "data": { 347 | "text/plain": [ 348 | "True" 349 | ] 350 | }, 351 | "execution_count": 15, 352 | "metadata": {}, 353 | "output_type": "execute_result" 354 | } 355 | ], 356 | "source": [ 357 | "10 <= 11" 358 | ] 359 | }, 360 | { 361 | "cell_type": "code", 362 | "execution_count": 16, 363 | "id": "eb820260", 364 | "metadata": {}, 365 | "outputs": [ 366 | { 367 | "data": { 368 | "text/plain": [ 369 | "True" 370 | ] 371 | }, 372 | "execution_count": 16, 373 | "metadata": {}, 374 | "output_type": "execute_result" 375 | } 376 | ], 377 | "source": [ 378 | "10 == 10" 379 | ] 380 | }, 381 | { 382 | "cell_type": "code", 383 | "execution_count": 17, 384 | "id": "84ad0efe", 385 | "metadata": {}, 386 | "outputs": [ 387 | { 388 | "data": { 389 | "text/plain": [ 390 | "False" 391 | ] 392 | }, 393 | "execution_count": 17, 394 | "metadata": {}, 395 | "output_type": "execute_result" 396 | } 397 | ], 398 | "source": [ 399 | "11 == 10" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": 19, 405 | "id": "33ef8667", 406 | "metadata": {}, 407 | "outputs": [ 408 | { 409 | "name": "stdout", 410 | "output_type": "stream", 411 | "text": [ 412 | "Enter your ATM pin: 1232\n" 413 | ] 414 | }, 415 | { 416 | "data": { 417 | "text/plain": [ 418 | "False" 419 | ] 420 | }, 421 | "execution_count": 19, 422 | "metadata": {}, 423 | "output_type": "execute_result" 424 | } 425 | ], 426 | "source": [ 427 | "a = int(input(\"Enter your ATM pin: \"))\n", 428 | "\n", 429 | "a == 1234" 430 | ] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "execution_count": 20, 435 | "id": "372eaf00", 436 | "metadata": {}, 437 | "outputs": [ 438 | { 439 | "data": { 440 | "text/plain": [ 441 | "False" 442 | ] 443 | }, 444 | "execution_count": 20, 445 | "metadata": {}, 446 | "output_type": "execute_result" 447 | } 448 | ], 449 | "source": [ 450 | "10 != 10" 451 | ] 452 | }, 453 | { 454 | "cell_type": "code", 455 | "execution_count": 21, 456 | "id": "ab7a895c", 457 | "metadata": {}, 458 | "outputs": [ 459 | { 460 | "data": { 461 | "text/plain": [ 462 | "True" 463 | ] 464 | }, 465 | "execution_count": 21, 466 | "metadata": {}, 467 | "output_type": "execute_result" 468 | } 469 | ], 470 | "source": [ 471 | "10 != 7" 472 | ] 473 | }, 474 | { 475 | "cell_type": "code", 476 | "execution_count": null, 477 | "id": "20dfb91d", 478 | "metadata": {}, 479 | "outputs": [], 480 | "source": [] 481 | } 482 | ], 483 | "metadata": { 484 | "kernelspec": { 485 | "display_name": "Python 3 (ipykernel)", 486 | "language": "python", 487 | "name": "python3" 488 | }, 489 | "language_info": { 490 | "codemirror_mode": { 491 | "name": "ipython", 492 | "version": 3 493 | }, 494 | "file_extension": ".py", 495 | "mimetype": "text/x-python", 496 | "name": "python", 497 | "nbconvert_exporter": "python", 498 | "pygments_lexer": "ipython3", 499 | "version": "3.9.12" 500 | } 501 | }, 502 | "nbformat": 4, 503 | "nbformat_minor": 5 504 | } 505 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/08_Operators Bitwise AND.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "32cdbfdb", 6 | "metadata": {}, 7 | "source": [ 8 | "# Bitwise Operators" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "id": "26419392", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "& -> bitwise and\n", 19 | "| -> bitwise or\n", 20 | "^ -> bitwise xor\n", 21 | "<< -> bitwise leftshift\n", 22 | ">> -> bitwise rightshift" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "id": "6b49f93c", 28 | "metadata": {}, 29 | "source": [ 30 | "# & -> bitwise and\n" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "id": "e3150dd8", 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "0\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "print(8 & 2)" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "id": "8d46ed98", 54 | "metadata": {}, 55 | "source": [ 56 | "# Binary Numbers" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "id": "887e7d6f", 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "1024 512 256 128 64 32 16 8 4 2 1\n", 67 | " 1 0 0 0\n", 68 | " 1 0\n", 69 | " 0 0 0 0\n", 70 | " 1 0 1 1\n", 71 | " 1 1\n", 72 | " 1 1 0 1 1\n", 73 | " 1 1 0 0 1" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "id": "8ab83c3e", 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "truth tables\n", 84 | "& \n", 85 | "0 & 0 -> 0 \n", 86 | "0 & 1 -> 0\n", 87 | "1 & 0 -> 0\n", 88 | "1 & 1 -> 1" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "id": "0fc892ff", 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "1000\n", 99 | "0010 &\n", 100 | "0000" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 3, 106 | "id": "2ebbe530", 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "3\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "print(11 & 3)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "id": "e2c33fba", 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [ 128 | "1011\n", 129 | "0011 &\n", 130 | "0011" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 4, 136 | "id": "f14c2e3a", 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "data": { 141 | "text/plain": [ 142 | "11" 143 | ] 144 | }, 145 | "execution_count": 4, 146 | "metadata": {}, 147 | "output_type": "execute_result" 148 | } 149 | ], 150 | "source": [ 151 | "27 & 11" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "id": "5bb24d18", 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [ 161 | "11011\n", 162 | "01011 &\n", 163 | "01011" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 5, 169 | "id": "9f1fdb6b", 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "data": { 174 | "text/plain": [ 175 | "25" 176 | ] 177 | }, 178 | "execution_count": 5, 179 | "metadata": {}, 180 | "output_type": "execute_result" 181 | } 182 | ], 183 | "source": [ 184 | "31 & 25" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": null, 190 | "id": "877d5a15", 191 | "metadata": {}, 192 | "outputs": [], 193 | "source": [ 194 | "11111\n", 195 | "11001 &\n", 196 | "11001" 197 | ] 198 | } 199 | ], 200 | "metadata": { 201 | "kernelspec": { 202 | "display_name": "Python 3 (ipykernel)", 203 | "language": "python", 204 | "name": "python3" 205 | }, 206 | "language_info": { 207 | "codemirror_mode": { 208 | "name": "ipython", 209 | "version": 3 210 | }, 211 | "file_extension": ".py", 212 | "mimetype": "text/x-python", 213 | "name": "python", 214 | "nbconvert_exporter": "python", 215 | "pygments_lexer": "ipython3", 216 | "version": "3.9.12" 217 | } 218 | }, 219 | "nbformat": 4, 220 | "nbformat_minor": 5 221 | } 222 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/09_Operators Bitwise OR.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e421d0b6", 6 | "metadata": {}, 7 | "source": [ 8 | "# Bitwise OR" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "id": "b1e9270b", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "& -> bitwise and\n", 19 | "| -> bitwise or\n", 20 | "^ -> bitwise xor\n", 21 | "<< -> bitwise leftshift\n", 22 | ">> -> bitwise rightshift" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 1, 28 | "id": "892f9fea", 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "10\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "print(10 | 8)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "id": "7c530d50", 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "1024 512 256 128 64 32 16 8 4 2 1\n", 51 | " 1 0 1 0\n", 52 | " 1 0 0 0\n", 53 | " 1 0 1 1 0\n", 54 | " 1 0 1 1 1" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "id": "d345f350", 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "truth table\n", 65 | "|\n", 66 | "0 | 0 -> 0\n", 67 | "0 | 1 -> 1\n", 68 | "1 | 0 -> 1\n", 69 | "1 | 1 -> 1" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "id": "366eec9c", 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "1010\n", 80 | "1000 |\n", 81 | "1010" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 2, 87 | "id": "d7cc28dd", 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "23\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "print(17 | 22)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "id": "c24ce992", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "10001\n", 110 | "10110 |\n", 111 | "10111 ---> 23" 112 | ] 113 | } 114 | ], 115 | "metadata": { 116 | "kernelspec": { 117 | "display_name": "Python 3 (ipykernel)", 118 | "language": "python", 119 | "name": "python3" 120 | }, 121 | "language_info": { 122 | "codemirror_mode": { 123 | "name": "ipython", 124 | "version": 3 125 | }, 126 | "file_extension": ".py", 127 | "mimetype": "text/x-python", 128 | "name": "python", 129 | "nbconvert_exporter": "python", 130 | "pygments_lexer": "ipython3", 131 | "version": "3.9.12" 132 | } 133 | }, 134 | "nbformat": 4, 135 | "nbformat_minor": 5 136 | } 137 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/10_Operator Bitwise XOR.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "af3d90e1", 6 | "metadata": {}, 7 | "source": [ 8 | "# Operator Bitwise XOR\n", 9 | "\n", 10 | "Watch the video in 1.5x speed to better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "6b731f3a", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "5\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "print(12 ^ 9)" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "id": "658deead", 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "1024 512 256 128 64 32 16 8 4 2 1\n", 39 | " 1 1 0 0\n", 40 | " 1 0 0 1\n", 41 | " 0 1 0 1\n", 42 | " 1 1 0 1 1\n", 43 | " 0 1 1 1 0" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "id": "6e2c0517", 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "truth table\n", 54 | "^\n", 55 | "0 ^ 0 -> 0\n", 56 | "0 ^ 1 -> 1\n", 57 | "1 ^ 0 -> 1\n", 58 | "1 ^ 1 -> 0" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "id": "eac14af2", 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "1100\n", 69 | "1001 ^\n", 70 | "0101" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 2, 76 | "id": "a7091268", 77 | "metadata": {}, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "14\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "print(21 ^ 27)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "id": "04c9b93c", 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "10101\n", 99 | "11011 ^\n", 100 | "01110" 101 | ] 102 | } 103 | ], 104 | "metadata": { 105 | "kernelspec": { 106 | "display_name": "Python 3 (ipykernel)", 107 | "language": "python", 108 | "name": "python3" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": { 112 | "name": "ipython", 113 | "version": 3 114 | }, 115 | "file_extension": ".py", 116 | "mimetype": "text/x-python", 117 | "name": "python", 118 | "nbconvert_exporter": "python", 119 | "pygments_lexer": "ipython3", 120 | "version": "3.9.12" 121 | } 122 | }, 123 | "nbformat": 4, 124 | "nbformat_minor": 5 125 | } 126 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/11_Operator Bitwise Left Shift.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "2392476f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Operator Bitwise Left Shift\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "d2d9fc2d", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "<<" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "id": "938cf88e", 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "name": "stdout", 31 | "output_type": "stream", 32 | "text": [ 33 | "40\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "print(10 << 2)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "id": "b2fe119d", 45 | "metadata": {}, 46 | "outputs": [], 47 | "source": [ 48 | "1024 512 256 128 64 32 16 8 4 2 1\n", 49 | " 1 0 1 0\n", 50 | " 0 0 1 0 1 0 0 0 \n", 51 | " 1 1 0 0 0 0 0 0" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "id": "9531f29f", 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "\n", 62 | "00001010\n", 63 | "\n", 64 | "00010100\n", 65 | "\n", 66 | "00101000" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 2, 72 | "id": "da47a2ce", 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "name": "stdout", 77 | "output_type": "stream", 78 | "text": [ 79 | "192\n" 80 | ] 81 | } 82 | ], 83 | "source": [ 84 | "print(24 << 3)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "id": "fb9a2294", 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "00011000\n", 95 | "\n", 96 | "11000000" 97 | ] 98 | } 99 | ], 100 | "metadata": { 101 | "kernelspec": { 102 | "display_name": "Python 3 (ipykernel)", 103 | "language": "python", 104 | "name": "python3" 105 | }, 106 | "language_info": { 107 | "codemirror_mode": { 108 | "name": "ipython", 109 | "version": 3 110 | }, 111 | "file_extension": ".py", 112 | "mimetype": "text/x-python", 113 | "name": "python", 114 | "nbconvert_exporter": "python", 115 | "pygments_lexer": "ipython3", 116 | "version": "3.9.12" 117 | } 118 | }, 119 | "nbformat": 4, 120 | "nbformat_minor": 5 121 | } 122 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/12_Operator Bitwise Right Shift.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "01115474", 6 | "metadata": {}, 7 | "source": [ 8 | "# Bitwise Right Shift\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "824f8d70", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | ">>" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "id": "4d5b08e9", 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "name": "stdout", 31 | "output_type": "stream", 32 | "text": [ 33 | "3\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "print(12 >> 2)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "id": "6aa2355f", 45 | "metadata": {}, 46 | "outputs": [], 47 | "source": [ 48 | "128 64 32 16 8 4 2 1\n", 49 | " 1 1 0 0\n", 50 | " 1 1\n", 51 | " 1 1 0 1 1\n", 52 | " 1 0 1 1 1 1\n", 53 | " 1 0 1 1" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "id": "61c87f96", 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "00001100\n", 64 | "\n", 65 | "00000110\n", 66 | "\n", 67 | "00000011" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 2, 73 | "id": "2d6dfddb", 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "name": "stdout", 78 | "output_type": "stream", 79 | "text": [ 80 | "3\n" 81 | ] 82 | } 83 | ], 84 | "source": [ 85 | "print(27 >> 3)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "id": "8dafffe4", 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "00001101\n", 96 | "\n", 97 | "00000110\n", 98 | "\n", 99 | "00000011\n" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 3, 105 | "id": "734d2bd5", 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "11\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "print(47 >> 2)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "id": "5c971303", 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "00101111\n", 128 | "\n", 129 | "00010111\n", 130 | "\n", 131 | "00001011\n" 132 | ] 133 | } 134 | ], 135 | "metadata": { 136 | "kernelspec": { 137 | "display_name": "Python 3 (ipykernel)", 138 | "language": "python", 139 | "name": "python3" 140 | }, 141 | "language_info": { 142 | "codemirror_mode": { 143 | "name": "ipython", 144 | "version": 3 145 | }, 146 | "file_extension": ".py", 147 | "mimetype": "text/x-python", 148 | "name": "python", 149 | "nbconvert_exporter": "python", 150 | "pygments_lexer": "ipython3", 151 | "version": "3.9.12" 152 | } 153 | }, 154 | "nbformat": 4, 155 | "nbformat_minor": 5 156 | } 157 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/13_Boolean and Logical Operators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "2b42139a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Boolean and Logical Operators\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "601149c9", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "# boolean operators\n", 21 | "\n", 22 | "True\n", 23 | "\n", 24 | "False\n" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "id": "322a34f8", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "# logical operators\n", 35 | "\n", 36 | "not\n", 37 | "and\n", 38 | "or" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 1, 44 | "id": "7ab82743", 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "False\n" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "print(not True)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 2, 62 | "id": "e70fddaf", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "True\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "print(not False)" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 3, 80 | "id": "266908ee", 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "ename": "SyntaxError", 85 | "evalue": "invalid syntax (941600843.py, line 1)", 86 | "output_type": "error", 87 | "traceback": [ 88 | "\u001b[1;36m Input \u001b[1;32mIn [3]\u001b[1;36m\u001b[0m\n\u001b[1;33m print(False not)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "print(False not)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "id": "979c50d5", 100 | "metadata": {}, 101 | "outputs": [], 102 | "source": [ 103 | "# truth table for and\n", 104 | "0 = False, 1 = True\n", 105 | "\n", 106 | "False and False = False\n", 107 | "False and True = False\n", 108 | "True and False = False\n", 109 | "True and True = True" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 4, 115 | "id": "936c2a02", 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "False\n" 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "print(False and True)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 5, 133 | "id": "ec650747", 134 | "metadata": {}, 135 | "outputs": [ 136 | { 137 | "name": "stdout", 138 | "output_type": "stream", 139 | "text": [ 140 | "False\n" 141 | ] 142 | } 143 | ], 144 | "source": [ 145 | "print(False and True and False and True)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "id": "25af6191", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "# truth table for or\n", 156 | "0 = False, 1 = True\n", 157 | "\n", 158 | "False or False = False\n", 159 | "False or True = True\n", 160 | "True or False = True\n", 161 | "True or True = True" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 6, 167 | "id": "e45a60b7", 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "name": "stdout", 172 | "output_type": "stream", 173 | "text": [ 174 | "True\n" 175 | ] 176 | } 177 | ], 178 | "source": [ 179 | "print(True or False or True or False or False)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "id": "1f87798b", 185 | "metadata": {}, 186 | "source": [ 187 | "## Combine all the logical operators in a Question" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "id": "6ab9fe23", 194 | "metadata": {}, 195 | "outputs": [], 196 | "source": [ 197 | "# priority\n", 198 | "\n", 199 | "1. not\n", 200 | "2. and\n", 201 | "3. or" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 7, 207 | "id": "f576c7a4", 208 | "metadata": {}, 209 | "outputs": [ 210 | { 211 | "name": "stdout", 212 | "output_type": "stream", 213 | "text": [ 214 | "True\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "print(False and not True or False and not False or True and not False and True)\n", 220 | "# False True True\n", 221 | "# False False True\n", 222 | "# True\n", 223 | "# True" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": null, 229 | "id": "594098c2", 230 | "metadata": {}, 231 | "outputs": [], 232 | "source": [] 233 | } 234 | ], 235 | "metadata": { 236 | "kernelspec": { 237 | "display_name": "Python 3 (ipykernel)", 238 | "language": "python", 239 | "name": "python3" 240 | }, 241 | "language_info": { 242 | "codemirror_mode": { 243 | "name": "ipython", 244 | "version": 3 245 | }, 246 | "file_extension": ".py", 247 | "mimetype": "text/x-python", 248 | "name": "python", 249 | "nbconvert_exporter": "python", 250 | "pygments_lexer": "ipython3", 251 | "version": "3.9.12" 252 | } 253 | }, 254 | "nbformat": 4, 255 | "nbformat_minor": 5 256 | } 257 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/2_Operators/14_Assignment and Compound Operators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9834988f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Assignment and Compound Operators\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "d47edd78", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "# Assignment\n", 21 | "=" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "id": "304a393c", 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "10\n", 35 | "20\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "a = 10\n", 41 | "\n", 42 | "print(a)\n", 43 | "\n", 44 | "a = 20\n", 45 | "\n", 46 | "print(a)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "id": "f6e9aa67", 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "# compound operators\n", 57 | "+=, -=, *= , /=, **=, //=, %=" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 2, 63 | "id": "4df58fbb", 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "15\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "a = 10\n", 76 | "\n", 77 | "a += 5 # a = a + 5\n", 78 | "\n", 79 | "print(a)" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 3, 85 | "id": "a00f6018", 86 | "metadata": {}, 87 | "outputs": [ 88 | { 89 | "name": "stdout", 90 | "output_type": "stream", 91 | "text": [ 92 | "8\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "a = 10\n", 98 | "\n", 99 | "a -= 2 # a = a - 2\n", 100 | "\n", 101 | "print(a)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 4, 107 | "id": "0ebc52ee", 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "10.0\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "b = 20\n", 120 | "\n", 121 | "b /= 2 # b = b / 2\n", 122 | "\n", 123 | "print(b)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 5, 129 | "id": "7fd0dde4", 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "name": "stdout", 134 | "output_type": "stream", 135 | "text": [ 136 | "27\n" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "c = 3\n", 142 | "\n", 143 | "c **= 3 # c = c ** 3\n", 144 | "\n", 145 | "print(c)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 6, 151 | "id": "33a064a7", 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "2\n" 159 | ] 160 | } 161 | ], 162 | "source": [ 163 | "d = 10\n", 164 | "\n", 165 | "d %= 4 # d = d % 4\n", 166 | "\n", 167 | "print(d)" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "id": "91c8e9f1", 174 | "metadata": {}, 175 | "outputs": [], 176 | "source": [] 177 | } 178 | ], 179 | "metadata": { 180 | "kernelspec": { 181 | "display_name": "Python 3 (ipykernel)", 182 | "language": "python", 183 | "name": "python3" 184 | }, 185 | "language_info": { 186 | "codemirror_mode": { 187 | "name": "ipython", 188 | "version": 3 189 | }, 190 | "file_extension": ".py", 191 | "mimetype": "text/x-python", 192 | "name": "python", 193 | "nbconvert_exporter": "python", 194 | "pygments_lexer": "ipython3", 195 | "version": "3.9.12" 196 | } 197 | }, 198 | "nbformat": 4, 199 | "nbformat_minor": 5 200 | } 201 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/3_Conditional Statements/.ipynb_checkpoints/15_Conditional Statements If and Else-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3323d39d", 6 | "metadata": {}, 7 | "source": [ 8 | "# Conditional Statements If and Else" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "f2ef8862", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Hello\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "a = 10\n", 27 | "\n", 28 | "if (a > 5):\n", 29 | " print(\"Hello\")" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "5acd583f", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "a = 20\n", 40 | "\n", 41 | "if 20 == 10:\n", 42 | " print(\"Hi\")" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 4, 48 | "id": "87b4a96f", 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "name": "stdout", 53 | "output_type": "stream", 54 | "text": [ 55 | "Enter your pin:1234\n", 56 | "Here is your cash\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "pin = 1234\n", 62 | "get_pin = int(input(\"Enter your pin:\"))\n", 63 | "\n", 64 | "if get_pin == pin:\n", 65 | " print(\"Here is your cash\")\n", 66 | "else:\n", 67 | " print(\"Your pin is incorrect\")" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 5, 73 | "id": "e94777f8", 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "ename": "SyntaxError", 78 | "evalue": "invalid syntax (4061035225.py, line 1)", 79 | "output_type": "error", 80 | "traceback": [ 81 | "\u001b[1;36m Input \u001b[1;32mIn [5]\u001b[1;36m\u001b[0m\n\u001b[1;33m else:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "else:\n", 87 | " print(\"Hi\")" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "id": "7707107e", 93 | "metadata": {}, 94 | "source": [ 95 | "#### Write a program to enter a number from user and print its absolute value?" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": null, 101 | "id": "9f18c617", 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "__________._____________\n", 106 | " -4 -2 -1 0 1 2 3 4\n", 107 | " \n", 108 | "|-2| = 2\n", 109 | "\n", 110 | "|-4| = 4" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 7, 116 | "id": "780a4b6b", 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "Enter a number:-7\n", 124 | "Absolute value = 7\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "n = int(input(\"Enter a number:\"))\n", 130 | "\n", 131 | "if n >= 0:\n", 132 | " print(\"Absolute value =\", n)\n", 133 | "else:\n", 134 | " print(\"Absolute value =\", n * (-1))" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "id": "4d599d36", 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [] 144 | } 145 | ], 146 | "metadata": { 147 | "kernelspec": { 148 | "display_name": "Python 3 (ipykernel)", 149 | "language": "python", 150 | "name": "python3" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": { 154 | "name": "ipython", 155 | "version": 3 156 | }, 157 | "file_extension": ".py", 158 | "mimetype": "text/x-python", 159 | "name": "python", 160 | "nbconvert_exporter": "python", 161 | "pygments_lexer": "ipython3", 162 | "version": "3.9.12" 163 | } 164 | }, 165 | "nbformat": 4, 166 | "nbformat_minor": 5 167 | } 168 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/3_Conditional Statements/.ipynb_checkpoints/16_Else If and Ternary Statement-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c4c94474", 6 | "metadata": {}, 7 | "source": [ 8 | "# Else If and Ternary Statement\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "760a991c", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "1\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "a = 10\n", 29 | "\n", 30 | "if a > 5:\n", 31 | " print(1)\n", 32 | "elif a == 10:\n", 33 | " print(2)\n", 34 | "else:\n", 35 | " print(3)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 2, 41 | "id": "691ebee4", 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "name": "stdout", 46 | "output_type": "stream", 47 | "text": [ 48 | "2\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "a = 10\n", 54 | "\n", 55 | "if a < 5:\n", 56 | " print(1)\n", 57 | "elif a == 10:\n", 58 | " print(2)\n", 59 | "else:\n", 60 | " print(3)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 3, 66 | "id": "0395fc89", 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "1\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "a = 10\n", 79 | "\n", 80 | "if a > 5:\n", 81 | " print(1)\n", 82 | "elif a == 10:\n", 83 | " print(2)\n", 84 | "else:\n", 85 | " print(3)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 4, 91 | "id": "7a0ab06f", 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "3\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "a = 11\n", 104 | "\n", 105 | "if a > 15:\n", 106 | " print(1)\n", 107 | "elif a == 10:\n", 108 | " print(2)\n", 109 | "else:\n", 110 | " print(3)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 5, 116 | "id": "81ead700", 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "3\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "a = 11\n", 129 | "\n", 130 | "if a > 15:\n", 131 | " print(1)\n", 132 | "elif a == 10:\n", 133 | " print(2)\n", 134 | "elif a == 5:\n", 135 | " print(4)\n", 136 | "else:\n", 137 | " print(3)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "id": "86feb0d5", 143 | "metadata": {}, 144 | "source": [ 145 | "### Ternary Statements" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "id": "0fabd1dc", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "? : " 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 6, 161 | "id": "1dc39970", 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "45\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "a = 10\n", 174 | "\n", 175 | "b = 45 if a > 5 else 100\n", 176 | "\n", 177 | "print(b)" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 7, 183 | "id": "c28c32e2", 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "name": "stdout", 188 | "output_type": "stream", 189 | "text": [ 190 | "100\n" 191 | ] 192 | } 193 | ], 194 | "source": [ 195 | "a = 10\n", 196 | "\n", 197 | "b = 45 if a > 15 else 100\n", 198 | "\n", 199 | "print(b)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "id": "a331608c", 206 | "metadata": {}, 207 | "outputs": [], 208 | "source": [] 209 | } 210 | ], 211 | "metadata": { 212 | "kernelspec": { 213 | "display_name": "Python 3 (ipykernel)", 214 | "language": "python", 215 | "name": "python3" 216 | }, 217 | "language_info": { 218 | "codemirror_mode": { 219 | "name": "ipython", 220 | "version": 3 221 | }, 222 | "file_extension": ".py", 223 | "mimetype": "text/x-python", 224 | "name": "python", 225 | "nbconvert_exporter": "python", 226 | "pygments_lexer": "ipython3", 227 | "version": "3.9.12" 228 | } 229 | }, 230 | "nbformat": 4, 231 | "nbformat_minor": 5 232 | } 233 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/3_Conditional Statements/.ipynb_checkpoints/17_Nested If and else-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e728d762", 6 | "metadata": {}, 7 | "source": [ 8 | "# Nested If and Else\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "a6b91eac", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "a = int(input(\"Enter a number: \"))\n", 21 | "\n", 22 | "if a > 5:\n", 23 | " print(1)\n", 24 | " if a > 8:\n", 25 | " print(2)\n", 26 | " else:\n", 27 | " print(3)\n", 28 | " if a == 9:\n", 29 | " print(4)\n", 30 | " elif a == 10:\n", 31 | " print(5)\n", 32 | " else:\n", 33 | " print(6)\n", 34 | "else:\n", 35 | " print(7)\n", 36 | " if a == 1:\n", 37 | " print(8)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "id": "6ee2a09e", 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [] 47 | } 48 | ], 49 | "metadata": { 50 | "kernelspec": { 51 | "display_name": "Python 3 (ipykernel)", 52 | "language": "python", 53 | "name": "python3" 54 | }, 55 | "language_info": { 56 | "codemirror_mode": { 57 | "name": "ipython", 58 | "version": 3 59 | }, 60 | "file_extension": ".py", 61 | "mimetype": "text/x-python", 62 | "name": "python", 63 | "nbconvert_exporter": "python", 64 | "pygments_lexer": "ipython3", 65 | "version": "3.9.12" 66 | } 67 | }, 68 | "nbformat": 4, 69 | "nbformat_minor": 5 70 | } 71 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/3_Conditional Statements/.ipynb_checkpoints/18_If and Else Practice Questions-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "0100814d", 6 | "metadata": {}, 7 | "source": [ 8 | "# Practice Questions\n", 9 | "\n", 10 | "**Write a program to enter a number from user and check if it is greater than 10 or not.**" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 3, 16 | "id": "569ed893", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "Enter a number: 100\n", 24 | "Greater\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "a = int(input(\"Enter a number: \"))\n", 30 | "\n", 31 | "if a > 10:\n", 32 | " print(\"Greater\")\n", 33 | "elif a == 10:\n", 34 | " print(\"Equal\")\n", 35 | "else:\n", 36 | " print(\"Smaller\")" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "id": "e03427ac", 42 | "metadata": {}, 43 | "source": [ 44 | "**Write a program to enter 3 numbers from use and print the greater number.**" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 6, 50 | "id": "b58eccb6", 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "Enter 1st number: 30\n", 58 | "Enter 2nd number: 20\n", 59 | "Enter 3rd number: 15\n", 60 | "Greater = 30\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "a = int(input(\"Enter 1st number: \"))\n", 66 | "b = int(input(\"Enter 2nd number: \"))\n", 67 | "c = int(input(\"Enter 3rd number: \"))\n", 68 | "\n", 69 | "if a >= b:\n", 70 | " if a >= c:\n", 71 | " print(\"Greater =\", a)\n", 72 | " else:\n", 73 | " print(\"Greater = \", c)\n", 74 | "else:\n", 75 | " if b >= c:\n", 76 | " print(\"Greater=\", b)\n", 77 | " else:\n", 78 | " print(\"Greater =\", c)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "id": "20b04617", 84 | "metadata": {}, 85 | "source": [ 86 | "**Write a program to enter a number between 0 to 9 and print its character format.**" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 8, 92 | "id": "8cb4576c", 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "Enter a number: 10\n", 100 | "Incorrect Value\n" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "a = int(input(\"Enter a number: \"))\n", 106 | "\n", 107 | "if a == 0:\n", 108 | " print(\"Zero\")\n", 109 | "elif a == 1:\n", 110 | " print(\"One\")\n", 111 | "elif a == 2:\n", 112 | " print(\"Two\")\n", 113 | "elif a == 3:\n", 114 | " print(\"Three\")\n", 115 | "elif a == 4:\n", 116 | " print(\"Four\")\n", 117 | "elif a == 5:\n", 118 | " print(\"Five\")\n", 119 | "elif a == 6:\n", 120 | " print(\"Six\")\n", 121 | "elif a == 7:\n", 122 | " print(\"Seven\")\n", 123 | "elif a == 8:\n", 124 | " print(\"Eight\")\n", 125 | "elif a == 9:\n", 126 | " print(\"Nine\")\n", 127 | "else:\n", 128 | " print(\"Incorrect Value\")" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "id": "35d1b036", 134 | "metadata": {}, 135 | "source": [ 136 | "**Write a program to enter a character from user and check if it is vowel or consonant.**" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 10, 142 | "id": "34bc7f26", 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "Enter a character: i\n", 150 | "Vowel\n" 151 | ] 152 | } 153 | ], 154 | "source": [ 155 | "ch = input(\"Enter a character: \")\n", 156 | "\n", 157 | "if ch == 'a':\n", 158 | " print(\"Vowel\")\n", 159 | "elif ch == 'e':\n", 160 | " print('Vowel')\n", 161 | "elif ch == 'i':\n", 162 | " print('Vowel')\n", 163 | "elif ch == 'o':\n", 164 | " print('Vowel')\n", 165 | "elif ch == 'u':\n", 166 | " print('Vowel')\n", 167 | "else:\n", 168 | " print(\"Consonant\")" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 12, 174 | "id": "f5f97a42", 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "Enter a character: z\n", 182 | "Consonant\n" 183 | ] 184 | } 185 | ], 186 | "source": [ 187 | "ch = input(\"Enter a character: \")\n", 188 | "\n", 189 | "if ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u':\n", 190 | " print(\"Vowel\")\n", 191 | "else:\n", 192 | " print(\"Consonant\")" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "id": "e17448e0", 199 | "metadata": {}, 200 | "outputs": [], 201 | "source": [] 202 | } 203 | ], 204 | "metadata": { 205 | "kernelspec": { 206 | "display_name": "Python 3 (ipykernel)", 207 | "language": "python", 208 | "name": "python3" 209 | }, 210 | "language_info": { 211 | "codemirror_mode": { 212 | "name": "ipython", 213 | "version": 3 214 | }, 215 | "file_extension": ".py", 216 | "mimetype": "text/x-python", 217 | "name": "python", 218 | "nbconvert_exporter": "python", 219 | "pygments_lexer": "ipython3", 220 | "version": "3.9.12" 221 | } 222 | }, 223 | "nbformat": 4, 224 | "nbformat_minor": 5 225 | } 226 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/3_Conditional Statements/15_Conditional Statements If and Else.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3323d39d", 6 | "metadata": {}, 7 | "source": [ 8 | "# Conditional Statements If and Else" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "f2ef8862", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Hello\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "a = 10\n", 27 | "\n", 28 | "if (a > 5):\n", 29 | " print(\"Hello\")" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "5acd583f", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "a = 20\n", 40 | "\n", 41 | "if 20 == 10:\n", 42 | " print(\"Hi\")" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 4, 48 | "id": "87b4a96f", 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "name": "stdout", 53 | "output_type": "stream", 54 | "text": [ 55 | "Enter your pin:1234\n", 56 | "Here is your cash\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "pin = 1234\n", 62 | "get_pin = int(input(\"Enter your pin:\"))\n", 63 | "\n", 64 | "if get_pin == pin:\n", 65 | " print(\"Here is your cash\")\n", 66 | "else:\n", 67 | " print(\"Your pin is incorrect\")" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 5, 73 | "id": "e94777f8", 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "ename": "SyntaxError", 78 | "evalue": "invalid syntax (4061035225.py, line 1)", 79 | "output_type": "error", 80 | "traceback": [ 81 | "\u001b[1;36m Input \u001b[1;32mIn [5]\u001b[1;36m\u001b[0m\n\u001b[1;33m else:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "else:\n", 87 | " print(\"Hi\")" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "id": "7707107e", 93 | "metadata": {}, 94 | "source": [ 95 | "#### Write a program to enter a number from user and print its absolute value?" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": null, 101 | "id": "9f18c617", 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "__________._____________\n", 106 | " -4 -2 -1 0 1 2 3 4\n", 107 | " \n", 108 | "|-2| = 2\n", 109 | "\n", 110 | "|-4| = 4" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 7, 116 | "id": "780a4b6b", 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "Enter a number:-7\n", 124 | "Absolute value = 7\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "n = int(input(\"Enter a number:\"))\n", 130 | "\n", 131 | "if n >= 0:\n", 132 | " print(\"Absolute value =\", n)\n", 133 | "else:\n", 134 | " print(\"Absolute value =\", n * (-1))" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "id": "4d599d36", 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [] 144 | } 145 | ], 146 | "metadata": { 147 | "kernelspec": { 148 | "display_name": "Python 3 (ipykernel)", 149 | "language": "python", 150 | "name": "python3" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": { 154 | "name": "ipython", 155 | "version": 3 156 | }, 157 | "file_extension": ".py", 158 | "mimetype": "text/x-python", 159 | "name": "python", 160 | "nbconvert_exporter": "python", 161 | "pygments_lexer": "ipython3", 162 | "version": "3.9.12" 163 | } 164 | }, 165 | "nbformat": 4, 166 | "nbformat_minor": 5 167 | } 168 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/3_Conditional Statements/16_Else If and Ternary Statement.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c4c94474", 6 | "metadata": {}, 7 | "source": [ 8 | "# Else If and Ternary Statement\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "760a991c", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "1\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "a = 10\n", 29 | "\n", 30 | "if a > 5:\n", 31 | " print(1)\n", 32 | "elif a == 10:\n", 33 | " print(2)\n", 34 | "else:\n", 35 | " print(3)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 2, 41 | "id": "691ebee4", 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "name": "stdout", 46 | "output_type": "stream", 47 | "text": [ 48 | "2\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "a = 10\n", 54 | "\n", 55 | "if a < 5:\n", 56 | " print(1)\n", 57 | "elif a == 10:\n", 58 | " print(2)\n", 59 | "else:\n", 60 | " print(3)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 3, 66 | "id": "0395fc89", 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "1\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "a = 10\n", 79 | "\n", 80 | "if a > 5:\n", 81 | " print(1)\n", 82 | "elif a == 10:\n", 83 | " print(2)\n", 84 | "else:\n", 85 | " print(3)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 4, 91 | "id": "7a0ab06f", 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "3\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "a = 11\n", 104 | "\n", 105 | "if a > 15:\n", 106 | " print(1)\n", 107 | "elif a == 10:\n", 108 | " print(2)\n", 109 | "else:\n", 110 | " print(3)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 5, 116 | "id": "81ead700", 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "3\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "a = 11\n", 129 | "\n", 130 | "if a > 15:\n", 131 | " print(1)\n", 132 | "elif a == 10:\n", 133 | " print(2)\n", 134 | "elif a == 5:\n", 135 | " print(4)\n", 136 | "else:\n", 137 | " print(3)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "id": "86feb0d5", 143 | "metadata": {}, 144 | "source": [ 145 | "### Ternary Statements" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "id": "0fabd1dc", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "? : " 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 6, 161 | "id": "1dc39970", 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "45\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "a = 10\n", 174 | "\n", 175 | "b = 45 if a > 5 else 100\n", 176 | "\n", 177 | "print(b)" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 7, 183 | "id": "c28c32e2", 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "name": "stdout", 188 | "output_type": "stream", 189 | "text": [ 190 | "100\n" 191 | ] 192 | } 193 | ], 194 | "source": [ 195 | "a = 10\n", 196 | "\n", 197 | "b = 45 if a > 15 else 100\n", 198 | "\n", 199 | "print(b)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "id": "a331608c", 206 | "metadata": {}, 207 | "outputs": [], 208 | "source": [] 209 | } 210 | ], 211 | "metadata": { 212 | "kernelspec": { 213 | "display_name": "Python 3 (ipykernel)", 214 | "language": "python", 215 | "name": "python3" 216 | }, 217 | "language_info": { 218 | "codemirror_mode": { 219 | "name": "ipython", 220 | "version": 3 221 | }, 222 | "file_extension": ".py", 223 | "mimetype": "text/x-python", 224 | "name": "python", 225 | "nbconvert_exporter": "python", 226 | "pygments_lexer": "ipython3", 227 | "version": "3.9.12" 228 | } 229 | }, 230 | "nbformat": 4, 231 | "nbformat_minor": 5 232 | } 233 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/3_Conditional Statements/17_Nested If and else.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e728d762", 6 | "metadata": {}, 7 | "source": [ 8 | "# Nested If and Else\n", 9 | "\n", 10 | "Watch the video in 1.5x speed for better experience.\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "a6b91eac", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "a = int(input(\"Enter a number: \"))\n", 21 | "\n", 22 | "if a > 5:\n", 23 | " print(1)\n", 24 | " if a > 8:\n", 25 | " print(2)\n", 26 | " else:\n", 27 | " print(3)\n", 28 | " if a == 9:\n", 29 | " print(4)\n", 30 | " elif a == 10:\n", 31 | " print(5)\n", 32 | " else:\n", 33 | " print(6)\n", 34 | "else:\n", 35 | " print(7)\n", 36 | " if a == 1:\n", 37 | " print(8)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "id": "6ee2a09e", 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [] 47 | } 48 | ], 49 | "metadata": { 50 | "kernelspec": { 51 | "display_name": "Python 3 (ipykernel)", 52 | "language": "python", 53 | "name": "python3" 54 | }, 55 | "language_info": { 56 | "codemirror_mode": { 57 | "name": "ipython", 58 | "version": 3 59 | }, 60 | "file_extension": ".py", 61 | "mimetype": "text/x-python", 62 | "name": "python", 63 | "nbconvert_exporter": "python", 64 | "pygments_lexer": "ipython3", 65 | "version": "3.9.12" 66 | } 67 | }, 68 | "nbformat": 4, 69 | "nbformat_minor": 5 70 | } 71 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/3_Conditional Statements/18_If and Else Practice Questions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "0100814d", 6 | "metadata": {}, 7 | "source": [ 8 | "# Practice Questions\n", 9 | "\n", 10 | "**Write a program to enter a number from user and check if it is greater than 10 or not.**" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 3, 16 | "id": "569ed893", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "Enter a number: 100\n", 24 | "Greater\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "a = int(input(\"Enter a number: \"))\n", 30 | "\n", 31 | "if a > 10:\n", 32 | " print(\"Greater\")\n", 33 | "elif a == 10:\n", 34 | " print(\"Equal\")\n", 35 | "else:\n", 36 | " print(\"Smaller\")" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "id": "e03427ac", 42 | "metadata": {}, 43 | "source": [ 44 | "**Write a program to enter 3 numbers from user and print the greater number.**" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 6, 50 | "id": "b58eccb6", 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "Enter 1st number: 30\n", 58 | "Enter 2nd number: 20\n", 59 | "Enter 3rd number: 15\n", 60 | "Greater = 30\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "a = int(input(\"Enter 1st number: \"))\n", 66 | "b = int(input(\"Enter 2nd number: \"))\n", 67 | "c = int(input(\"Enter 3rd number: \"))\n", 68 | "\n", 69 | "if a >= b:\n", 70 | " if a >= c:\n", 71 | " print(\"Greater =\", a)\n", 72 | " else:\n", 73 | " print(\"Greater = \", c)\n", 74 | "else:\n", 75 | " if b >= c:\n", 76 | " print(\"Greater=\", b)\n", 77 | " else:\n", 78 | " print(\"Greater =\", c)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "id": "20b04617", 84 | "metadata": {}, 85 | "source": [ 86 | "**Write a program to enter a number between 0 to 9 and print its character format.**" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 8, 92 | "id": "8cb4576c", 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "Enter a number: 10\n", 100 | "Incorrect Value\n" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "a = int(input(\"Enter a number: \"))\n", 106 | "\n", 107 | "if a == 0:\n", 108 | " print(\"Zero\")\n", 109 | "elif a == 1:\n", 110 | " print(\"One\")\n", 111 | "elif a == 2:\n", 112 | " print(\"Two\")\n", 113 | "elif a == 3:\n", 114 | " print(\"Three\")\n", 115 | "elif a == 4:\n", 116 | " print(\"Four\")\n", 117 | "elif a == 5:\n", 118 | " print(\"Five\")\n", 119 | "elif a == 6:\n", 120 | " print(\"Six\")\n", 121 | "elif a == 7:\n", 122 | " print(\"Seven\")\n", 123 | "elif a == 8:\n", 124 | " print(\"Eight\")\n", 125 | "elif a == 9:\n", 126 | " print(\"Nine\")\n", 127 | "else:\n", 128 | " print(\"Incorrect Value\")" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "id": "35d1b036", 134 | "metadata": {}, 135 | "source": [ 136 | "**Write a program to enter a character from user and check if it is vowel or consonant.**" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 10, 142 | "id": "34bc7f26", 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "Enter a character: i\n", 150 | "Vowel\n" 151 | ] 152 | } 153 | ], 154 | "source": [ 155 | "ch = input(\"Enter a character: \")\n", 156 | "\n", 157 | "if ch == 'a':\n", 158 | " print(\"Vowel\")\n", 159 | "elif ch == 'e':\n", 160 | " print('Vowel')\n", 161 | "elif ch == 'i':\n", 162 | " print('Vowel')\n", 163 | "elif ch == 'o':\n", 164 | " print('Vowel')\n", 165 | "elif ch == 'u':\n", 166 | " print('Vowel')\n", 167 | "else:\n", 168 | " print(\"Consonant\")" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 12, 174 | "id": "f5f97a42", 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "Enter a character: z\n", 182 | "Consonant\n" 183 | ] 184 | } 185 | ], 186 | "source": [ 187 | "ch = input(\"Enter a character: \")\n", 188 | "\n", 189 | "if ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u':\n", 190 | " print(\"Vowel\")\n", 191 | "else:\n", 192 | " print(\"Consonant\")" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "id": "e17448e0", 199 | "metadata": {}, 200 | "outputs": [], 201 | "source": [] 202 | } 203 | ], 204 | "metadata": { 205 | "kernelspec": { 206 | "display_name": "Python 3 (ipykernel)", 207 | "language": "python", 208 | "name": "python3" 209 | }, 210 | "language_info": { 211 | "codemirror_mode": { 212 | "name": "ipython", 213 | "version": 3 214 | }, 215 | "file_extension": ".py", 216 | "mimetype": "text/x-python", 217 | "name": "python", 218 | "nbconvert_exporter": "python", 219 | "pygments_lexer": "ipython3", 220 | "version": "3.9.12" 221 | } 222 | }, 223 | "nbformat": 4, 224 | "nbformat_minor": 5 225 | } 226 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/.ipynb_checkpoints/19_While Loop-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/.ipynb_checkpoints/20_Number Series questions using While Loops-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "0fbf6454", 6 | "metadata": {}, 7 | "source": [ 8 | "# Number Series questions using \n", 9 | "# While Loops" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "id": "2e4402f6", 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "1 2 3 4 5 6 7 8 9 10" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 1, 25 | "id": "2145416f", 26 | "metadata": {}, 27 | "outputs": [ 28 | { 29 | "name": "stdout", 30 | "output_type": "stream", 31 | "text": [ 32 | "Hello\n", 33 | "User\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "print(\"Hello\")\n", 39 | "print(\"User\")" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": null, 45 | "id": "e1d08e4a", 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "\"Hello\" + \"\\n\"" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 2, 55 | "id": "37330d98", 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "Hello\n", 63 | "User\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "print(\"Hello\", end='\\n')\n", 69 | "print(\"User\")" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 3, 75 | "id": "b383890c", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "Hello User\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "print(\"Hello\", end=' ')\n", 88 | "print(\"User\")" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 4, 94 | "id": "afd4dc0e", 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "Hello+User\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "print(\"Hello\", end='+')\n", 107 | "print(\"User\")" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 5, 113 | "id": "0f454bc7", 114 | "metadata": {}, 115 | "outputs": [ 116 | { 117 | "name": "stdout", 118 | "output_type": "stream", 119 | "text": [ 120 | "HelloUser\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "print(\"Hello\", end='')\n", 126 | "print(\"User\")" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 6, 132 | "id": "d092e91c", 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "Hello\tUser\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "print(\"Hello\", end='\\t')\n", 145 | "print(\"User\")" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "id": "d72d7534", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "1 2 3 4 5 6 7 8 9 10" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 8, 161 | "id": "df5f51bd", 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "1 2 3 4 5 6 7 8 9 10 " 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "i = 1\n", 174 | "\n", 175 | "while i <= 10:\n", 176 | " print(i, end=' ')\n", 177 | " i += 1" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 9, 183 | "id": "dc311e85", 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "name": "stdout", 188 | "output_type": "stream", 189 | "text": [ 190 | "20\n", 191 | "10\n" 192 | ] 193 | } 194 | ], 195 | "source": [ 196 | "a = 10\n", 197 | "\n", 198 | "# a = a + 10\n", 199 | "\n", 200 | "print(a + 10)\n", 201 | "\n", 202 | "print(a)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": null, 208 | "id": "937b3e61", 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [ 212 | "1 4 9 16 25 36 49 64 81 100" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 10, 218 | "id": "9601193d", 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "1 4 9 16 25 36 49 64 81 100 " 226 | ] 227 | } 228 | ], 229 | "source": [ 230 | "i = 1\n", 231 | "\n", 232 | "while i <= 10:\n", 233 | " print(i*i, end=\" \")\n", 234 | " i += 1" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": null, 240 | "id": "ac78b595", 241 | "metadata": {}, 242 | "outputs": [], 243 | "source": [] 244 | } 245 | ], 246 | "metadata": { 247 | "kernelspec": { 248 | "display_name": "Python 3 (ipykernel)", 249 | "language": "python", 250 | "name": "python3" 251 | }, 252 | "language_info": { 253 | "codemirror_mode": { 254 | "name": "ipython", 255 | "version": 3 256 | }, 257 | "file_extension": ".py", 258 | "mimetype": "text/x-python", 259 | "name": "python", 260 | "nbconvert_exporter": "python", 261 | "pygments_lexer": "ipython3", 262 | "version": "3.9.12" 263 | } 264 | }, 265 | "nbformat": 4, 266 | "nbformat_minor": 5 267 | } 268 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/.ipynb_checkpoints/21_Number Series Practice Questions and Answers-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/.ipynb_checkpoints/22_Break and Continue Statements with While Loops-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "4fe5957a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Break and Continue Statements \n", 9 | "# with While Loops\n", 10 | "\n", 11 | "Watch the video in 1.5x speed for better experience." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 5, 17 | "id": "9a707a63", 18 | "metadata": {}, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "1\n", 25 | "Finish\n" 26 | ] 27 | } 28 | ], 29 | "source": [ 30 | "i = 1\n", 31 | "\n", 32 | "while i <= 10:\n", 33 | " print(i)\n", 34 | " break\n", 35 | "\n", 36 | "print(\"Finish\")" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 6, 42 | "id": "e4dc09e5", 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "1\n", 50 | "2\n", 51 | "3\n", 52 | "4\n", 53 | "5\n", 54 | "Finish\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "i = 1\n", 60 | "\n", 61 | "while i <= 10:\n", 62 | " if i == 5:\n", 63 | " print(i)\n", 64 | " break\n", 65 | " else:\n", 66 | " print(i)\n", 67 | " i += 1\n", 68 | "\n", 69 | "print(\"Finish\")" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "id": "28440ee4", 75 | "metadata": {}, 76 | "source": [ 77 | "# continue statement" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 7, 83 | "id": "b37c3c9a", 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "1\n", 91 | "3\n", 92 | "5\n", 93 | "7\n", 94 | "9\n", 95 | "11\n", 96 | "Indore\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "i = 0\n", 102 | "\n", 103 | "while i <= 10:\n", 104 | " i += 1\n", 105 | " if i%2 == 0:\n", 106 | " continue\n", 107 | " else:\n", 108 | " print(i)\n", 109 | "\n", 110 | "print(\"Indore\")" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "id": "6fb5104e", 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [] 120 | } 121 | ], 122 | "metadata": { 123 | "kernelspec": { 124 | "display_name": "Python 3 (ipykernel)", 125 | "language": "python", 126 | "name": "python3" 127 | }, 128 | "language_info": { 129 | "codemirror_mode": { 130 | "name": "ipython", 131 | "version": 3 132 | }, 133 | "file_extension": ".py", 134 | "mimetype": "text/x-python", 135 | "name": "python", 136 | "nbconvert_exporter": "python", 137 | "pygments_lexer": "ipython3", 138 | "version": "3.9.12" 139 | } 140 | }, 141 | "nbformat": 4, 142 | "nbformat_minor": 5 143 | } 144 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/.ipynb_checkpoints/23_Nested While Loop in Python-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/.ipynb_checkpoints/25_Logic Building Practice Questions and Solutions in Python-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e26472bd", 6 | "metadata": {}, 7 | "source": [ 8 | "# Logic Building Practice \n", 9 | "# Questions and Solutions in Python\n", 10 | "\n", 11 | "Watch the video at 1.5x speed for better experience." 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "f288b566", 17 | "metadata": {}, 18 | "source": [ 19 | "**Write a program to enter a number from the user
\n", 20 | "and print reverse of that number,**\n" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "id": "8a40b504", 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "143 % 10 = 3\n", 31 | "143 // 10 = 14\n", 32 | "\n", 33 | "14 % 10 = 4\n", 34 | "14 // 10 = 1\n", 35 | "\n", 36 | "1 % 10 = 1\n", 37 | "1 // 10 = 0" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 1, 43 | "id": "2db4c867", 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "name": "stdout", 48 | "output_type": "stream", 49 | "text": [ 50 | "Enter a number: 143\n", 51 | "341" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "n = int(input(\"Enter a number: \"))\n", 57 | "\n", 58 | "while n > 0:\n", 59 | " r = n % 10\n", 60 | " print(r, end='') # 341\n", 61 | " n = n // 10" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "id": "c50d4baf", 67 | "metadata": {}, 68 | "source": [ 69 | "**Write a program to enter a number from the user
\n", 70 | "and print addition of its individual digits,**\n", 71 | "\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "id": "dfde20cc", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "143 = 1 + 4 + 3 = 8\n", 82 | "\n", 83 | "0 = add\n", 84 | "1 = 1 add\n", 85 | "4 = 5 add\n", 86 | "3 = 8 add" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 3, 92 | "id": "1f5cf355", 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "Enter a number: 167\n", 100 | "Addition = 14\n" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "n = int(input(\"Enter a number: \"))\n", 106 | "add = 0\n", 107 | "\n", 108 | "while n > 0:\n", 109 | " r = n % 10\n", 110 | " add = add + r # add = 0, 3, 7, 8\n", 111 | " n = n // 10\n", 112 | "\n", 113 | "print(\"Addition =\", add)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "id": "ed178e75", 119 | "metadata": {}, 120 | "source": [ 121 | "**Write a program to enter a number from the user
\n", 122 | "and print reverse of it with dynamic method,**\n", 123 | "\n" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 4, 129 | "id": "166588c3", 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "name": "stdout", 134 | "output_type": "stream", 135 | "text": [ 136 | "Enter a number: 143\n", 137 | "Reverse = 341\n", 138 | "682\n" 139 | ] 140 | } 141 | ], 142 | "source": [ 143 | "n = int(input(\"Enter a number: \"))\n", 144 | "add = 0\n", 145 | "\n", 146 | "while n > 0:\n", 147 | " r = n % 10\n", 148 | " add = add * 10 + r # add = 0, 3, 34, 341\n", 149 | " n = n // 10\n", 150 | "\n", 151 | "print(\"Reverse =\", add)\n", 152 | "print(add * 2)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "id": "2d91fb2b", 158 | "metadata": {}, 159 | "source": [ 160 | "\n", 161 | "**Write a program to enter a number from the user
\n", 162 | "and check if it palindrome or not,**\n", 163 | "\n" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "id": "8a7b0bf5", 170 | "metadata": {}, 171 | "outputs": [], 172 | "source": [ 173 | "121 = 121 = palindrome\n", 174 | "\n", 175 | "143 = 341 => not palindrome" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 6, 181 | "id": "ee31ec8a", 182 | "metadata": {}, 183 | "outputs": [ 184 | { 185 | "name": "stdout", 186 | "output_type": "stream", 187 | "text": [ 188 | "Enter a number: 121\n", 189 | "Not a Palindrome\n" 190 | ] 191 | } 192 | ], 193 | "source": [ 194 | "n = int(input(\"Enter a number: \"))\n", 195 | "add = 0\n", 196 | "\n", 197 | "while n > 0:\n", 198 | " r = n % 10\n", 199 | " add = add * 10 + r\n", 200 | " n = n // 10\n", 201 | "\n", 202 | "if add == n:\n", 203 | " print(\"Palindrome\")\n", 204 | "else:\n", 205 | " print(\"Not a Palindrome\")" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 8, 211 | "id": "05dfbdda", 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "name": "stdout", 216 | "output_type": "stream", 217 | "text": [ 218 | "Enter a number: 121\n", 219 | "Palindrome\n" 220 | ] 221 | } 222 | ], 223 | "source": [ 224 | "n = int(input(\"Enter a number: \"))\n", 225 | "call = n\n", 226 | "add = 0\n", 227 | "\n", 228 | "while n > 0:\n", 229 | " r = n % 10\n", 230 | " add = add * 10 + r\n", 231 | " n = n // 10\n", 232 | "\n", 233 | "if add == call:\n", 234 | " print(\"Palindrome\")\n", 235 | "else:\n", 236 | " print(\"Not a Palindrome\")" 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "id": "14cd6c98", 242 | "metadata": {}, 243 | "source": [ 244 | "\n", 245 | "**Write a program to enter a number from the user
\n", 246 | "and check if it armstrong number or not,**" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": null, 252 | "id": "a269453c", 253 | "metadata": {}, 254 | "outputs": [], 255 | "source": [ 256 | "143\n", 257 | "\n", 258 | "cube(1) + cube(4) + cube(3) = 1 + 64 + 27 = 92" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 10, 264 | "id": "4e3d343b", 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "92" 271 | ] 272 | }, 273 | "execution_count": 10, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "153\n", 280 | "\n", 281 | "cube(1) + cube(5) + cube(3) = 1 + 125 + 27 = 153" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 13, 287 | "id": "612b8368", 288 | "metadata": {}, 289 | "outputs": [ 290 | { 291 | "name": "stdout", 292 | "output_type": "stream", 293 | "text": [ 294 | "Enter a number: 370\n", 295 | "Armstrong Number\n" 296 | ] 297 | } 298 | ], 299 | "source": [ 300 | "n = int(input(\"Enter a number: \"))\n", 301 | "call = n\n", 302 | "add = 0\n", 303 | "\n", 304 | "while n > 0:\n", 305 | " r = n % 10\n", 306 | " add = add + r*r*r # add = 0, 27\n", 307 | " n = n // 10\n", 308 | "\n", 309 | "if add == call:\n", 310 | " print(\"Armstrong Number\")\n", 311 | "else:\n", 312 | " print(\"Not an Armstrong Number\")" 313 | ] 314 | }, 315 | { 316 | "cell_type": "code", 317 | "execution_count": null, 318 | "id": "14c43061", 319 | "metadata": {}, 320 | "outputs": [], 321 | "source": [] 322 | } 323 | ], 324 | "metadata": { 325 | "kernelspec": { 326 | "display_name": "Python 3 (ipykernel)", 327 | "language": "python", 328 | "name": "python3" 329 | }, 330 | "language_info": { 331 | "codemirror_mode": { 332 | "name": "ipython", 333 | "version": 3 334 | }, 335 | "file_extension": ".py", 336 | "mimetype": "text/x-python", 337 | "name": "python", 338 | "nbconvert_exporter": "python", 339 | "pygments_lexer": "ipython3", 340 | "version": "3.9.12" 341 | } 342 | }, 343 | "nbformat": 4, 344 | "nbformat_minor": 5 345 | } 346 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/19_While Loop.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e6efb0e6", 6 | "metadata": {}, 7 | "source": [ 8 | "# While Loop" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "69f69ea5", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "India\n", 22 | "India\n", 23 | "India\n", 24 | "India\n", 25 | "India\n" 26 | ] 27 | } 28 | ], 29 | "source": [ 30 | "i = 1\n", 31 | "\n", 32 | "while i <= 5 :\n", 33 | " print(\"India\")\n", 34 | " i += 1" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "id": "a4f11b98", 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "1\n", 45 | "2\n", 46 | "3\n", 47 | "4\n", 48 | "5" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 2, 54 | "id": "1f573f00", 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "1\n", 62 | "2\n", 63 | "3\n", 64 | "4\n", 65 | "5\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "i = 1\n", 71 | "\n", 72 | "while i <= 5:\n", 73 | " print(i)\n", 74 | " i += 1" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "id": "846aec51", 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "1\n", 85 | "2\n", 86 | "3\n", 87 | "4\n", 88 | "5\n", 89 | "6\n", 90 | "7\n", 91 | "8\n", 92 | "9\n", 93 | "10" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 3, 99 | "id": "728cfdc4", 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "1\n", 107 | "2\n", 108 | "3\n", 109 | "4\n", 110 | "5\n", 111 | "6\n", 112 | "7\n", 113 | "8\n", 114 | "9\n", 115 | "10\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "i = 1\n", 121 | "\n", 122 | "while i <= 10:\n", 123 | " print(i)\n", 124 | " i += 1" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": null, 130 | "id": "72401f43", 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [] 134 | } 135 | ], 136 | "metadata": { 137 | "kernelspec": { 138 | "display_name": "Python 3 (ipykernel)", 139 | "language": "python", 140 | "name": "python3" 141 | }, 142 | "language_info": { 143 | "codemirror_mode": { 144 | "name": "ipython", 145 | "version": 3 146 | }, 147 | "file_extension": ".py", 148 | "mimetype": "text/x-python", 149 | "name": "python", 150 | "nbconvert_exporter": "python", 151 | "pygments_lexer": "ipython3", 152 | "version": "3.9.12" 153 | } 154 | }, 155 | "nbformat": 4, 156 | "nbformat_minor": 5 157 | } 158 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/20_Number Series questions using While Loops.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "0fbf6454", 6 | "metadata": {}, 7 | "source": [ 8 | "# Number Series questions using \n", 9 | "# While Loops" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "id": "2e4402f6", 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "1 2 3 4 5 6 7 8 9 10" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 1, 25 | "id": "2145416f", 26 | "metadata": {}, 27 | "outputs": [ 28 | { 29 | "name": "stdout", 30 | "output_type": "stream", 31 | "text": [ 32 | "Hello\n", 33 | "User\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "print(\"Hello\")\n", 39 | "print(\"User\")" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": null, 45 | "id": "e1d08e4a", 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "\"Hello\" + \"\\n\"" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 2, 55 | "id": "37330d98", 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "Hello\n", 63 | "User\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "print(\"Hello\", end='\\n')\n", 69 | "print(\"User\")" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 3, 75 | "id": "b383890c", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "Hello User\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "print(\"Hello\", end=' ')\n", 88 | "print(\"User\")" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 4, 94 | "id": "afd4dc0e", 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "Hello+User\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "print(\"Hello\", end='+')\n", 107 | "print(\"User\")" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 5, 113 | "id": "0f454bc7", 114 | "metadata": {}, 115 | "outputs": [ 116 | { 117 | "name": "stdout", 118 | "output_type": "stream", 119 | "text": [ 120 | "HelloUser\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "print(\"Hello\", end='')\n", 126 | "print(\"User\")" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 6, 132 | "id": "d092e91c", 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "Hello\tUser\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "print(\"Hello\", end='\\t')\n", 145 | "print(\"User\")" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "id": "d72d7534", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "1 2 3 4 5 6 7 8 9 10" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 8, 161 | "id": "df5f51bd", 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "1 2 3 4 5 6 7 8 9 10 " 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "i = 1\n", 174 | "\n", 175 | "while i <= 10:\n", 176 | " print(i, end=' ')\n", 177 | " i += 1" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 9, 183 | "id": "dc311e85", 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "name": "stdout", 188 | "output_type": "stream", 189 | "text": [ 190 | "20\n", 191 | "10\n" 192 | ] 193 | } 194 | ], 195 | "source": [ 196 | "a = 10\n", 197 | "\n", 198 | "# a = a + 10\n", 199 | "\n", 200 | "print(a + 10)\n", 201 | "\n", 202 | "print(a)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": null, 208 | "id": "937b3e61", 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [ 212 | "1 4 9 16 25 36 49 64 81 100" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 10, 218 | "id": "9601193d", 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "1 4 9 16 25 36 49 64 81 100 " 226 | ] 227 | } 228 | ], 229 | "source": [ 230 | "i = 1\n", 231 | "\n", 232 | "while i <= 10:\n", 233 | " print(i*i, end=\" \")\n", 234 | " i += 1" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": null, 240 | "id": "ac78b595", 241 | "metadata": {}, 242 | "outputs": [], 243 | "source": [] 244 | } 245 | ], 246 | "metadata": { 247 | "kernelspec": { 248 | "display_name": "Python 3 (ipykernel)", 249 | "language": "python", 250 | "name": "python3" 251 | }, 252 | "language_info": { 253 | "codemirror_mode": { 254 | "name": "ipython", 255 | "version": 3 256 | }, 257 | "file_extension": ".py", 258 | "mimetype": "text/x-python", 259 | "name": "python", 260 | "nbconvert_exporter": "python", 261 | "pygments_lexer": "ipython3", 262 | "version": "3.9.12" 263 | } 264 | }, 265 | "nbformat": 4, 266 | "nbformat_minor": 5 267 | } 268 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/21_Number Series Practice Questions and Answers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "61e364c5", 6 | "metadata": {}, 7 | "source": [ 8 | "# Number Series Practice Questions and Answers\n", 9 | "\n", 10 | "Watch the video at 1.5x speed for better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "id": "b20f20e2", 16 | "metadata": {}, 17 | "source": [ 18 | "**Write a program to print first 10 even numbers**" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "id": "4a3513de", 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "2 4 6 8 10 12 14 16 18 20" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 1, 34 | "id": "0b2a21ea", 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "2 4 6 8 10 12 14 16 18 20 " 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "i = 2\n", 47 | "\n", 48 | "while i <= 20:\n", 49 | " print(i, end=' ')\n", 50 | " i += 2" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 2, 56 | "id": "dbbfffc3", 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "2 4 6 8 10 12 14 16 18 20 " 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "i = 1\n", 69 | "\n", 70 | "while i <= 20:\n", 71 | " if i%2 == 0:\n", 72 | " print(i, end=' ')\n", 73 | " i += 1" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "id": "c7070d6e", 79 | "metadata": {}, 80 | "source": [ 81 | "**Write a program to print first 10 odd numbers**" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 3, 87 | "id": "aebdb4c9", 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "1 3 5 7 9 11 13 15 17 19 " 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "i = 1\n", 100 | "\n", 101 | "while i <= 20:\n", 102 | " print(i, end=' ')\n", 103 | " i += 2" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 4, 109 | "id": "ab8bfe68", 110 | "metadata": {}, 111 | "outputs": [ 112 | { 113 | "name": "stdout", 114 | "output_type": "stream", 115 | "text": [ 116 | "1 3 5 7 9 11 13 15 17 19 " 117 | ] 118 | } 119 | ], 120 | "source": [ 121 | "i = 1\n", 122 | "\n", 123 | "while i <= 20:\n", 124 | " if i%2 == 1:\n", 125 | " print(i, end=' ')\n", 126 | " i += 1" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "id": "5af1ba99", 132 | "metadata": {}, 133 | "source": [ 134 | "**Write a program to print following series**" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "id": "c4def24d", 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [ 144 | "1/1 2/4 3/9 4/16 5/25 6/36 7/49 8/64 9/81 10/100" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 6, 150 | "id": "4dd27316", 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "name": "stdout", 155 | "output_type": "stream", 156 | "text": [ 157 | "1 / 1 2 / 4 3 / 9 4 / 16 5 / 25 6 / 36 7 / 49 8 / 64 9 / 81 10 / 100 " 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "i = 1\n", 163 | "\n", 164 | "while i <= 10:\n", 165 | " print(i,\"/\", i*i, end=' ')\n", 166 | " i += 1" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 7, 172 | "id": "c0cb406f", 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "name": "stdout", 177 | "output_type": "stream", 178 | "text": [ 179 | "1/1 2/4 3/9 4/16 5/25 6/36 7/49 8/64 9/81 10/100 " 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "i = 1\n", 185 | "\n", 186 | "while i <= 10:\n", 187 | " print(i, end='/')\n", 188 | " print(i*i, end=' ')\n", 189 | " i += 1" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "id": "524b50dc", 196 | "metadata": {}, 197 | "outputs": [], 198 | "source": [ 199 | "1+2+3+4+5+6+7+8+9+10" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 8, 205 | "id": "23ce4418", 206 | "metadata": {}, 207 | "outputs": [ 208 | { 209 | "name": "stdout", 210 | "output_type": "stream", 211 | "text": [ 212 | "1+2+3+4+5+6+7+8+9+10+" 213 | ] 214 | } 215 | ], 216 | "source": [ 217 | "i = 1\n", 218 | "\n", 219 | "while i <= 10:\n", 220 | " print(i, end='+')\n", 221 | " i += 1" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 9, 227 | "id": "c9ad62d9", 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "1+2+3+4+5+6+7+8+9+10\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "i = 1\n", 240 | "\n", 241 | "while i <= 10:\n", 242 | " if i < 10:\n", 243 | " print(i, end='+')\n", 244 | " else:\n", 245 | " print(i)\n", 246 | " i += 1" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": null, 252 | "id": "c6b4eb8a", 253 | "metadata": {}, 254 | "outputs": [], 255 | "source": [] 256 | } 257 | ], 258 | "metadata": { 259 | "kernelspec": { 260 | "display_name": "Python 3 (ipykernel)", 261 | "language": "python", 262 | "name": "python3" 263 | }, 264 | "language_info": { 265 | "codemirror_mode": { 266 | "name": "ipython", 267 | "version": 3 268 | }, 269 | "file_extension": ".py", 270 | "mimetype": "text/x-python", 271 | "name": "python", 272 | "nbconvert_exporter": "python", 273 | "pygments_lexer": "ipython3", 274 | "version": "3.9.12" 275 | } 276 | }, 277 | "nbformat": 4, 278 | "nbformat_minor": 5 279 | } 280 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/22_Break and Continue Statements with While Loops.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "4fe5957a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Break and Continue Statements \n", 9 | "# with While Loops\n", 10 | "\n", 11 | "Watch the video in 1.5x speed for better experience." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 5, 17 | "id": "9a707a63", 18 | "metadata": {}, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "1\n", 25 | "Finish\n" 26 | ] 27 | } 28 | ], 29 | "source": [ 30 | "i = 1\n", 31 | "\n", 32 | "while i <= 10:\n", 33 | " print(i)\n", 34 | " break\n", 35 | "\n", 36 | "print(\"Finish\")" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 6, 42 | "id": "e4dc09e5", 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "1\n", 50 | "2\n", 51 | "3\n", 52 | "4\n", 53 | "5\n", 54 | "Finish\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "i = 1\n", 60 | "\n", 61 | "while i <= 10:\n", 62 | " if i == 5:\n", 63 | " print(i)\n", 64 | " break\n", 65 | " else:\n", 66 | " print(i)\n", 67 | " i += 1\n", 68 | "\n", 69 | "print(\"Finish\")" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "id": "28440ee4", 75 | "metadata": {}, 76 | "source": [ 77 | "# continue statement" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 7, 83 | "id": "b37c3c9a", 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "1\n", 91 | "3\n", 92 | "5\n", 93 | "7\n", 94 | "9\n", 95 | "11\n", 96 | "Indore\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "i = 0\n", 102 | "\n", 103 | "while i <= 10:\n", 104 | " i += 1\n", 105 | " if i%2 == 0:\n", 106 | " continue\n", 107 | " else:\n", 108 | " print(i)\n", 109 | "\n", 110 | "print(\"Indore\")" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "id": "6fb5104e", 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [] 120 | } 121 | ], 122 | "metadata": { 123 | "kernelspec": { 124 | "display_name": "Python 3 (ipykernel)", 125 | "language": "python", 126 | "name": "python3" 127 | }, 128 | "language_info": { 129 | "codemirror_mode": { 130 | "name": "ipython", 131 | "version": 3 132 | }, 133 | "file_extension": ".py", 134 | "mimetype": "text/x-python", 135 | "name": "python", 136 | "nbconvert_exporter": "python", 137 | "pygments_lexer": "ipython3", 138 | "version": "3.9.12" 139 | } 140 | }, 141 | "nbformat": 4, 142 | "nbformat_minor": 5 143 | } 144 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/23_Nested While Loop in Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ed5fb122", 6 | "metadata": {}, 7 | "source": [ 8 | "# Nested While Loop in Python\n", 9 | "\n", 10 | "Watch the video at 1.5x speed for better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "6b9d81a1", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "11 12 13\n", 21 | "21 22 23\n", 22 | "31 32 33" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 2, 28 | "id": "e0a36b78", 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "1 1 1 2 1 3 \n", 36 | "\n", 37 | "\n" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "i = 1\n", 43 | "j = 1\n", 44 | "\n", 45 | "while i <= 3:\n", 46 | " \n", 47 | " while j <= 3:\n", 48 | " print(i,j, end=' ')\n", 49 | " j += 1\n", 50 | " print()\n", 51 | " i += 1" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "id": "470435c2", 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "11 12 13\n", 62 | "21 22 23\n", 63 | "31 32 33" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "id": "897c1db9", 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "name": "stdout", 74 | "output_type": "stream", 75 | "text": [ 76 | "1 1 1 2 1 3 \n", 77 | "2 1 2 2 2 3 \n", 78 | "3 1 3 2 3 3 \n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "i = 1\n", 84 | "# j = 1\n", 85 | "\n", 86 | "while i <= 3:\n", 87 | " j = 1\n", 88 | " while j <= 3:\n", 89 | " print(i,j, end=' ')\n", 90 | " j += 1\n", 91 | " print()\n", 92 | " i += 1" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 4, 98 | "id": "35032d30", 99 | "metadata": {}, 100 | "outputs": [ 101 | { 102 | "name": "stdout", 103 | "output_type": "stream", 104 | "text": [ 105 | "11 12 13 \n", 106 | "21 22 23 \n", 107 | "31 32 33 \n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "i = 1\n", 113 | "# j = 1\n", 114 | "\n", 115 | "while i <= 3:\n", 116 | " j = 1\n", 117 | " while j <= 3:\n", 118 | " print(i, end='')\n", 119 | " print(j, end=' ')\n", 120 | " j += 1\n", 121 | " print()\n", 122 | " i += 1" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 1, 128 | "id": "9e9e777a", 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "name": "stdout", 133 | "output_type": "stream", 134 | "text": [ 135 | "Hi\n", 136 | "\n", 137 | "Bye\n" 138 | ] 139 | } 140 | ], 141 | "source": [ 142 | "print(\"Hi\")\n", 143 | "print()\n", 144 | "print(\"Bye\")" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "id": "eed4ef1d", 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [] 154 | } 155 | ], 156 | "metadata": { 157 | "kernelspec": { 158 | "display_name": "Python 3 (ipykernel)", 159 | "language": "python", 160 | "name": "python3" 161 | }, 162 | "language_info": { 163 | "codemirror_mode": { 164 | "name": "ipython", 165 | "version": 3 166 | }, 167 | "file_extension": ".py", 168 | "mimetype": "text/x-python", 169 | "name": "python", 170 | "nbconvert_exporter": "python", 171 | "pygments_lexer": "ipython3", 172 | "version": "3.9.12" 173 | } 174 | }, 175 | "nbformat": 4, 176 | "nbformat_minor": 5 177 | } 178 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/4_While Loop/25_Logic Building Practice Questions and Solutions in Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e26472bd", 6 | "metadata": {}, 7 | "source": [ 8 | "# Logic Building Practice \n", 9 | "# Questions and Solutions in Python\n", 10 | "\n", 11 | "Watch the video at 1.5x speed for better experience." 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "f288b566", 17 | "metadata": {}, 18 | "source": [ 19 | "**Write a program to enter a number from the user
\n", 20 | "and print reverse of that number,**\n" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "id": "8a40b504", 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "143 % 10 = 3\n", 31 | "143 // 10 = 14\n", 32 | "\n", 33 | "14 % 10 = 4\n", 34 | "14 // 10 = 1\n", 35 | "\n", 36 | "1 % 10 = 1\n", 37 | "1 // 10 = 0" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 1, 43 | "id": "2db4c867", 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "name": "stdout", 48 | "output_type": "stream", 49 | "text": [ 50 | "Enter a number: 143\n", 51 | "341" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "n = int(input(\"Enter a number: \"))\n", 57 | "\n", 58 | "while n > 0:\n", 59 | " r = n % 10\n", 60 | " print(r, end='') # 341\n", 61 | " n = n // 10" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "id": "c50d4baf", 67 | "metadata": {}, 68 | "source": [ 69 | "**Write a program to enter a number from the user
\n", 70 | "and print addition of its individual digits,**\n", 71 | "\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "id": "dfde20cc", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "143 = 1 + 4 + 3 = 8\n", 82 | "\n", 83 | "0 = add\n", 84 | "1 = 1 add\n", 85 | "4 = 5 add\n", 86 | "3 = 8 add" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 3, 92 | "id": "1f5cf355", 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "Enter a number: 167\n", 100 | "Addition = 14\n" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "n = int(input(\"Enter a number: \"))\n", 106 | "add = 0\n", 107 | "\n", 108 | "while n > 0:\n", 109 | " r = n % 10\n", 110 | " add = add + r # add = 0, 3, 7, 8\n", 111 | " n = n // 10\n", 112 | "\n", 113 | "print(\"Addition =\", add)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "id": "ed178e75", 119 | "metadata": {}, 120 | "source": [ 121 | "**Write a program to enter a number from the user
\n", 122 | "and print reverse of it with dynamic method,**\n", 123 | "\n" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 4, 129 | "id": "166588c3", 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "name": "stdout", 134 | "output_type": "stream", 135 | "text": [ 136 | "Enter a number: 143\n", 137 | "Reverse = 341\n", 138 | "682\n" 139 | ] 140 | } 141 | ], 142 | "source": [ 143 | "n = int(input(\"Enter a number: \"))\n", 144 | "add = 0\n", 145 | "\n", 146 | "while n > 0:\n", 147 | " r = n % 10\n", 148 | " add = add * 10 + r # add = 0, 3, 34, 341\n", 149 | " n = n // 10\n", 150 | "\n", 151 | "print(\"Reverse =\", add)\n", 152 | "print(add * 2)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "id": "2d91fb2b", 158 | "metadata": {}, 159 | "source": [ 160 | "\n", 161 | "**Write a program to enter a number from the user
\n", 162 | "and check if it palindrome or not,**\n", 163 | "\n" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "id": "8a7b0bf5", 170 | "metadata": {}, 171 | "outputs": [], 172 | "source": [ 173 | "121 = 121 = palindrome\n", 174 | "\n", 175 | "143 = 341 => not palindrome" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 6, 181 | "id": "ee31ec8a", 182 | "metadata": {}, 183 | "outputs": [ 184 | { 185 | "name": "stdout", 186 | "output_type": "stream", 187 | "text": [ 188 | "Enter a number: 121\n", 189 | "Not a Palindrome\n" 190 | ] 191 | } 192 | ], 193 | "source": [ 194 | "n = int(input(\"Enter a number: \"))\n", 195 | "add = 0\n", 196 | "\n", 197 | "while n > 0:\n", 198 | " r = n % 10\n", 199 | " add = add * 10 + r\n", 200 | " n = n // 10\n", 201 | "\n", 202 | "if add == n:\n", 203 | " print(\"Palindrome\")\n", 204 | "else:\n", 205 | " print(\"Not a Palindrome\")" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 8, 211 | "id": "05dfbdda", 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "name": "stdout", 216 | "output_type": "stream", 217 | "text": [ 218 | "Enter a number: 121\n", 219 | "Palindrome\n" 220 | ] 221 | } 222 | ], 223 | "source": [ 224 | "n = int(input(\"Enter a number: \"))\n", 225 | "call = n\n", 226 | "add = 0\n", 227 | "\n", 228 | "while n > 0:\n", 229 | " r = n % 10\n", 230 | " add = add * 10 + r\n", 231 | " n = n // 10\n", 232 | "\n", 233 | "if add == call:\n", 234 | " print(\"Palindrome\")\n", 235 | "else:\n", 236 | " print(\"Not a Palindrome\")" 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "id": "14cd6c98", 242 | "metadata": {}, 243 | "source": [ 244 | "\n", 245 | "**Write a program to enter a number from the user
\n", 246 | "and check if it armstrong number or not,**" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": null, 252 | "id": "a269453c", 253 | "metadata": {}, 254 | "outputs": [], 255 | "source": [ 256 | "143\n", 257 | "\n", 258 | "cube(1) + cube(4) + cube(3) = 1 + 64 + 27 = 92" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 10, 264 | "id": "4e3d343b", 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "92" 271 | ] 272 | }, 273 | "execution_count": 10, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "153\n", 280 | "\n", 281 | "cube(1) + cube(5) + cube(3) = 1 + 125 + 27 = 153" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 13, 287 | "id": "612b8368", 288 | "metadata": {}, 289 | "outputs": [ 290 | { 291 | "name": "stdout", 292 | "output_type": "stream", 293 | "text": [ 294 | "Enter a number: 370\n", 295 | "Armstrong Number\n" 296 | ] 297 | } 298 | ], 299 | "source": [ 300 | "n = int(input(\"Enter a number: \"))\n", 301 | "call = n\n", 302 | "add = 0\n", 303 | "\n", 304 | "while n > 0:\n", 305 | " r = n % 10\n", 306 | " add = add + r*r*r # add = 0, 27\n", 307 | " n = n // 10\n", 308 | "\n", 309 | "if add == call:\n", 310 | " print(\"Armstrong Number\")\n", 311 | "else:\n", 312 | " print(\"Not an Armstrong Number\")" 313 | ] 314 | }, 315 | { 316 | "cell_type": "code", 317 | "execution_count": null, 318 | "id": "14c43061", 319 | "metadata": {}, 320 | "outputs": [], 321 | "source": [] 322 | } 323 | ], 324 | "metadata": { 325 | "kernelspec": { 326 | "display_name": "Python 3 (ipykernel)", 327 | "language": "python", 328 | "name": "python3" 329 | }, 330 | "language_info": { 331 | "codemirror_mode": { 332 | "name": "ipython", 333 | "version": 3 334 | }, 335 | "file_extension": ".py", 336 | "mimetype": "text/x-python", 337 | "name": "python", 338 | "nbconvert_exporter": "python", 339 | "pygments_lexer": "ipython3", 340 | "version": "3.9.12" 341 | } 342 | }, 343 | "nbformat": 4, 344 | "nbformat_minor": 5 345 | } 346 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/5_List/.ipynb_checkpoints/26_List Basics-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "81f993e9", 6 | "metadata": {}, 7 | "source": [ 8 | "# List\n", 9 | "\n", 10 | "Watch the video at 1.5x speed for better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "ff5e6f39", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "a = 10\n", 21 | "b = 20\n", 22 | "c = 30" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 1, 28 | "id": "f1a211da", 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "[10, 20, 30]\n", 36 | "\n" 37 | ] 38 | } 39 | ], 40 | "source": [ 41 | "l = [10, 20, 30]\n", 42 | "\n", 43 | "print(l)\n", 44 | "\n", 45 | "print(type(l))" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 3, 51 | "id": "66eb0915", 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "[10, 'Indore', True, 11.5]\n", 59 | "\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "l = [10, \"Indore\", True, 11.5]\n", 65 | "\n", 66 | "print(l)\n", 67 | "\n", 68 | "print(type(l))" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 4, 74 | "id": "dbb10ba8", 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "[10, 20, 30, 'A', 22.5]\n", 82 | "30\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "l = [10,20,30,\"A\",22.5]\n", 88 | "# 0 1 2 3 4\n", 89 | "\n", 90 | "print(l)\n", 91 | "\n", 92 | "print(l[2])" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 5, 98 | "id": "d9f95be3", 99 | "metadata": {}, 100 | "outputs": [ 101 | { 102 | "name": "stdout", 103 | "output_type": "stream", 104 | "text": [ 105 | "10\n" 106 | ] 107 | } 108 | ], 109 | "source": [ 110 | "print(l[0])" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 6, 116 | "id": "dc56209b", 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "A\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "print(l[3])" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 7, 134 | "id": "1509936a", 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "# a = 10\n", 139 | "# b = 20\n", 140 | "# c = 30\n", 141 | "\n", 142 | "# l[0] = 10\n", 143 | "# l[1] = 20\n", 144 | "# l[2] = 30" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 8, 150 | "id": "9efd349e", 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "name": "stdout", 155 | "output_type": "stream", 156 | "text": [ 157 | "[10, 20, 30, 'A', 22.5]\n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "print(l)" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 9, 168 | "id": "37c378ea", 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "name": "stdout", 173 | "output_type": "stream", 174 | "text": [ 175 | "[100, 20, 30, 'A', 22.5]\n" 176 | ] 177 | } 178 | ], 179 | "source": [ 180 | "l[0] = 100\n", 181 | "\n", 182 | "print(l) # list is mutable object" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 10, 188 | "id": "c90b5043", 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "ename": "IndexError", 193 | "evalue": "list assignment index out of range", 194 | "output_type": "error", 195 | "traceback": [ 196 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 197 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 198 | "Input \u001b[1;32mIn [10]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m l[\u001b[38;5;241m6\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m400\u001b[39m\n", 199 | "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "l[6] = 400" 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 11, 210 | "id": "3a62b51c", 211 | "metadata": {}, 212 | "outputs": [ 213 | { 214 | "name": "stdout", 215 | "output_type": "stream", 216 | "text": [ 217 | "[100, 20, 30, 'A', 22.5]\n" 218 | ] 219 | } 220 | ], 221 | "source": [ 222 | "print(l)" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 12, 228 | "id": "07f0769d", 229 | "metadata": {}, 230 | "outputs": [], 231 | "source": [ 232 | "# -5 -4 -3 -2 -1\n", 233 | "l = [100, 20, 30, 'A', 22.5]\n", 234 | "# 0 1 2 3 4" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 13, 240 | "id": "9b4a7b5d", 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "name": "stdout", 245 | "output_type": "stream", 246 | "text": [ 247 | "[100, 20, 30, 'A', 22.5]\n" 248 | ] 249 | } 250 | ], 251 | "source": [ 252 | "print(l)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 14, 258 | "id": "f645aa68", 259 | "metadata": {}, 260 | "outputs": [ 261 | { 262 | "name": "stdout", 263 | "output_type": "stream", 264 | "text": [ 265 | "22.5\n" 266 | ] 267 | } 268 | ], 269 | "source": [ 270 | "print(l[-1])" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": 15, 276 | "id": "007abb6d", 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "name": "stdout", 281 | "output_type": "stream", 282 | "text": [ 283 | "20\n" 284 | ] 285 | } 286 | ], 287 | "source": [ 288 | "print(l[-4])" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 16, 294 | "id": "69b47112", 295 | "metadata": {}, 296 | "outputs": [ 297 | { 298 | "name": "stdout", 299 | "output_type": "stream", 300 | "text": [ 301 | "20\n", 302 | "20\n" 303 | ] 304 | } 305 | ], 306 | "source": [ 307 | "print(l[1])\n", 308 | "print(l[-4])" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": null, 314 | "id": "18fea188", 315 | "metadata": {}, 316 | "outputs": [], 317 | "source": [] 318 | } 319 | ], 320 | "metadata": { 321 | "kernelspec": { 322 | "display_name": "Python 3 (ipykernel)", 323 | "language": "python", 324 | "name": "python3" 325 | }, 326 | "language_info": { 327 | "codemirror_mode": { 328 | "name": "ipython", 329 | "version": 3 330 | }, 331 | "file_extension": ".py", 332 | "mimetype": "text/x-python", 333 | "name": "python", 334 | "nbconvert_exporter": "python", 335 | "pygments_lexer": "ipython3", 336 | "version": "3.9.12" 337 | } 338 | }, 339 | "nbformat": 4, 340 | "nbformat_minor": 5 341 | } 342 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/5_List/26_List Basics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "81f993e9", 6 | "metadata": {}, 7 | "source": [ 8 | "# List\n", 9 | "\n", 10 | "Watch the video at 1.5x speed for better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "ff5e6f39", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "a = 10\n", 21 | "b = 20\n", 22 | "c = 30" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 1, 28 | "id": "f1a211da", 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "[10, 20, 30]\n", 36 | "\n" 37 | ] 38 | } 39 | ], 40 | "source": [ 41 | "l = [10, 20, 30]\n", 42 | "\n", 43 | "print(l)\n", 44 | "\n", 45 | "print(type(l))" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 3, 51 | "id": "66eb0915", 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "[10, 'Indore', True, 11.5]\n", 59 | "\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "l = [10, \"Indore\", True, 11.5]\n", 65 | "\n", 66 | "print(l)\n", 67 | "\n", 68 | "print(type(l))" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 4, 74 | "id": "dbb10ba8", 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "[10, 20, 30, 'A', 22.5]\n", 82 | "30\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "l = [10,20,30,\"A\",22.5]\n", 88 | "# 0 1 2 3 4\n", 89 | "\n", 90 | "print(l)\n", 91 | "\n", 92 | "print(l[2])" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 5, 98 | "id": "d9f95be3", 99 | "metadata": {}, 100 | "outputs": [ 101 | { 102 | "name": "stdout", 103 | "output_type": "stream", 104 | "text": [ 105 | "10\n" 106 | ] 107 | } 108 | ], 109 | "source": [ 110 | "print(l[0])" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 6, 116 | "id": "dc56209b", 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "A\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "print(l[3])" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 7, 134 | "id": "1509936a", 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "# a = 10\n", 139 | "# b = 20\n", 140 | "# c = 30\n", 141 | "\n", 142 | "# l[0] = 10\n", 143 | "# l[1] = 20\n", 144 | "# l[2] = 30" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 8, 150 | "id": "9efd349e", 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "name": "stdout", 155 | "output_type": "stream", 156 | "text": [ 157 | "[10, 20, 30, 'A', 22.5]\n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "print(l)" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 9, 168 | "id": "37c378ea", 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "name": "stdout", 173 | "output_type": "stream", 174 | "text": [ 175 | "[100, 20, 30, 'A', 22.5]\n" 176 | ] 177 | } 178 | ], 179 | "source": [ 180 | "l[0] = 100\n", 181 | "\n", 182 | "print(l) # list is mutable object" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 10, 188 | "id": "c90b5043", 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "ename": "IndexError", 193 | "evalue": "list assignment index out of range", 194 | "output_type": "error", 195 | "traceback": [ 196 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 197 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 198 | "Input \u001b[1;32mIn [10]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m l[\u001b[38;5;241m6\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m400\u001b[39m\n", 199 | "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "l[6] = 400" 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 11, 210 | "id": "3a62b51c", 211 | "metadata": {}, 212 | "outputs": [ 213 | { 214 | "name": "stdout", 215 | "output_type": "stream", 216 | "text": [ 217 | "[100, 20, 30, 'A', 22.5]\n" 218 | ] 219 | } 220 | ], 221 | "source": [ 222 | "print(l)" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 12, 228 | "id": "07f0769d", 229 | "metadata": {}, 230 | "outputs": [], 231 | "source": [ 232 | "# -5 -4 -3 -2 -1\n", 233 | "l = [100, 20, 30, 'A', 22.5]\n", 234 | "# 0 1 2 3 4" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 13, 240 | "id": "9b4a7b5d", 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "name": "stdout", 245 | "output_type": "stream", 246 | "text": [ 247 | "[100, 20, 30, 'A', 22.5]\n" 248 | ] 249 | } 250 | ], 251 | "source": [ 252 | "print(l)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 14, 258 | "id": "f645aa68", 259 | "metadata": {}, 260 | "outputs": [ 261 | { 262 | "name": "stdout", 263 | "output_type": "stream", 264 | "text": [ 265 | "22.5\n" 266 | ] 267 | } 268 | ], 269 | "source": [ 270 | "print(l[-1])" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": 15, 276 | "id": "007abb6d", 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "name": "stdout", 281 | "output_type": "stream", 282 | "text": [ 283 | "20\n" 284 | ] 285 | } 286 | ], 287 | "source": [ 288 | "print(l[-4])" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 16, 294 | "id": "69b47112", 295 | "metadata": {}, 296 | "outputs": [ 297 | { 298 | "name": "stdout", 299 | "output_type": "stream", 300 | "text": [ 301 | "20\n", 302 | "20\n" 303 | ] 304 | } 305 | ], 306 | "source": [ 307 | "print(l[1])\n", 308 | "print(l[-4])" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": null, 314 | "id": "18fea188", 315 | "metadata": {}, 316 | "outputs": [], 317 | "source": [] 318 | } 319 | ], 320 | "metadata": { 321 | "kernelspec": { 322 | "display_name": "Python 3 (ipykernel)", 323 | "language": "python", 324 | "name": "python3" 325 | }, 326 | "language_info": { 327 | "codemirror_mode": { 328 | "name": "ipython", 329 | "version": 3 330 | }, 331 | "file_extension": ".py", 332 | "mimetype": "text/x-python", 333 | "name": "python", 334 | "nbconvert_exporter": "python", 335 | "pygments_lexer": "ipython3", 336 | "version": "3.9.12" 337 | } 338 | }, 339 | "nbformat": 4, 340 | "nbformat_minor": 5 341 | } 342 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/6_String/.ipynb_checkpoints/30_String Basics-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "911057cd", 6 | "metadata": {}, 7 | "source": [ 8 | "# String Basics\n", 9 | "\n", 10 | "Watch the video at 1.5x speed for better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "7dc8e3fc", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "indore\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "s = 'indore'\n", 30 | "\n", 31 | "print(s)\n", 32 | "\n", 33 | "print(type(s))" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 2, 39 | "id": "13adf4e4", 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "A\n", 47 | "\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "s = 'A'\n", 53 | "\n", 54 | "print(s)\n", 55 | "\n", 56 | "print(type(s))" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 3, 62 | "id": "14908ec3", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "M\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "s = 'Machine'\n", 75 | "# 0123456\n", 76 | "\n", 77 | "print(s[0])" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 4, 83 | "id": "4a4484bd", 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "e\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "print(s[6])" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 5, 101 | "id": "4891138f", 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "ename": "IndexError", 106 | "evalue": "string index out of range", 107 | "output_type": "error", 108 | "traceback": [ 109 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 110 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 111 | "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43ms\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m9\u001b[39;49m\u001b[43m]\u001b[49m)\n", 112 | "\u001b[1;31mIndexError\u001b[0m: string index out of range" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "print(s[9])" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 6, 123 | "id": "36ccf2fb", 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "e\n" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "# -1\n", 136 | "s = 'Machine'\n", 137 | "# 0123456\n", 138 | "\n", 139 | "print(s[-1])" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 7, 145 | "id": "2250b4a0", 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "name": "stdout", 150 | "output_type": "stream", 151 | "text": [ 152 | "Learning\n", 153 | "\n" 154 | ] 155 | } 156 | ], 157 | "source": [ 158 | "s = \"Learning\"\n", 159 | "\n", 160 | "print(s)\n", 161 | "\n", 162 | "print(type(s))" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 8, 168 | "id": "e9f72b61", 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "name": "stdout", 173 | "output_type": "stream", 174 | "text": [ 175 | "\"Hello\"\n" 176 | ] 177 | } 178 | ], 179 | "source": [ 180 | "s = '\"Hello\"'\n", 181 | "\n", 182 | "print(s)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 9, 188 | "id": "471ab27c", 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "name": "stdout", 193 | "output_type": "stream", 194 | "text": [ 195 | "\"\n" 196 | ] 197 | } 198 | ], 199 | "source": [ 200 | "print(s[0])" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 11, 206 | "id": "62cb0500", 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "ename": "SyntaxError", 211 | "evalue": "invalid syntax (1513794406.py, line 1)", 212 | "output_type": "error", 213 | "traceback": [ 214 | "\u001b[1;36m Input \u001b[1;32mIn [11]\u001b[1;36m\u001b[0m\n\u001b[1;33m s = 'It's'\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "s = 'It's'\n", 220 | "\n", 221 | "print(s)" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 12, 227 | "id": "64a13a49", 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "It's\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "s = \"It's\"\n", 240 | "print(s)" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 13, 246 | "id": "22400c72", 247 | "metadata": {}, 248 | "outputs": [ 249 | { 250 | "name": "stdout", 251 | "output_type": "stream", 252 | "text": [ 253 | "\n", 254 | "\n" 255 | ] 256 | } 257 | ], 258 | "source": [ 259 | "# empty strings\n", 260 | "\n", 261 | "s = ''\n", 262 | "\n", 263 | "print(s)\n", 264 | "\n", 265 | "print(type(s))" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": null, 271 | "id": "9376728a", 272 | "metadata": {}, 273 | "outputs": [], 274 | "source": [ 275 | "s = \"ABC\"" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": 14, 281 | "id": "365c660a", 282 | "metadata": {}, 283 | "outputs": [ 284 | { 285 | "name": "stdout", 286 | "output_type": "stream", 287 | "text": [ 288 | "True\n" 289 | ] 290 | } 291 | ], 292 | "source": [ 293 | "print(bool(\" \"))" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": 15, 299 | "id": "3f932473", 300 | "metadata": {}, 301 | "outputs": [ 302 | { 303 | "name": "stdout", 304 | "output_type": "stream", 305 | "text": [ 306 | "False\n" 307 | ] 308 | } 309 | ], 310 | "source": [ 311 | "print(bool(''))" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 16, 317 | "id": "8fb5ec71", 318 | "metadata": {}, 319 | "outputs": [ 320 | { 321 | "name": "stdout", 322 | "output_type": "stream", 323 | "text": [ 324 | "True\n" 325 | ] 326 | } 327 | ], 328 | "source": [ 329 | "print(bool(1))" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": 17, 335 | "id": "0e3ec645", 336 | "metadata": {}, 337 | "outputs": [ 338 | { 339 | "name": "stdout", 340 | "output_type": "stream", 341 | "text": [ 342 | "False\n" 343 | ] 344 | } 345 | ], 346 | "source": [ 347 | "print(bool(0))" 348 | ] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "execution_count": 18, 353 | "id": "c6e6f358", 354 | "metadata": {}, 355 | "outputs": [ 356 | { 357 | "name": "stdout", 358 | "output_type": "stream", 359 | "text": [ 360 | "ABCD\n" 361 | ] 362 | } 363 | ], 364 | "source": [ 365 | "# concatenation\n", 366 | "\n", 367 | "s = \"A\" + \"BCD\"\n", 368 | "\n", 369 | "print(s)" 370 | ] 371 | }, 372 | { 373 | "cell_type": "code", 374 | "execution_count": 19, 375 | "id": "34df52e9", 376 | "metadata": {}, 377 | "outputs": [ 378 | { 379 | "name": "stdout", 380 | "output_type": "stream", 381 | "text": [ 382 | "A BCD\n" 383 | ] 384 | } 385 | ], 386 | "source": [ 387 | "s = \"A \" + \"BCD\"\n", 388 | "\n", 389 | "print(s)" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "execution_count": null, 395 | "id": "87794b70", 396 | "metadata": {}, 397 | "outputs": [], 398 | "source": [ 399 | "# immutable objects\n", 400 | "\n", 401 | "s = 'India'\n", 402 | "\n", 403 | "s[3] = \"A\"\n" 404 | ] 405 | } 406 | ], 407 | "metadata": { 408 | "kernelspec": { 409 | "display_name": "Python 3 (ipykernel)", 410 | "language": "python", 411 | "name": "python3" 412 | }, 413 | "language_info": { 414 | "codemirror_mode": { 415 | "name": "ipython", 416 | "version": 3 417 | }, 418 | "file_extension": ".py", 419 | "mimetype": "text/x-python", 420 | "name": "python", 421 | "nbconvert_exporter": "python", 422 | "pygments_lexer": "ipython3", 423 | "version": "3.9.12" 424 | } 425 | }, 426 | "nbformat": 4, 427 | "nbformat_minor": 5 428 | } 429 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/6_String/.ipynb_checkpoints/31_String Slicing-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a4def3de", 6 | "metadata": {}, 7 | "source": [ 8 | "# String Slicing\n", 9 | "\n", 10 | "Watch the video at 1.5x speed for better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "9bebb0c0", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "c\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "s = \"communication\"\n", 29 | "# 0123456789\n", 30 | "\n", 31 | "print(s[0])" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "id": "145895a6", 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "comm\n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "print(s[0:4])" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 3, 55 | "id": "7a5d2488", 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "mmunic\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "print(s[2:8])" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 4, 73 | "id": "a808f7ff", 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "name": "stdout", 78 | "output_type": "stream", 79 | "text": [ 80 | "\n" 81 | ] 82 | } 83 | ], 84 | "source": [ 85 | "print(s[4:1])" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 5, 91 | "id": "4a47cde8", 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "data": { 96 | "text/plain": [ 97 | "''" 98 | ] 99 | }, 100 | "execution_count": 5, 101 | "metadata": {}, 102 | "output_type": "execute_result" 103 | } 104 | ], 105 | "source": [ 106 | "s[4:1]" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 6, 112 | "id": "516f7dcd", 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "True\n", 120 | "False\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "a = \" \" # -> 32\n", 126 | "\n", 127 | "b = \"\"\n", 128 | "\n", 129 | "print(bool(a))\n", 130 | "\n", 131 | "print(bool(b))" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 7, 137 | "id": "f1dd6671", 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "name": "stdout", 142 | "output_type": "stream", 143 | "text": [ 144 | "\n", 145 | "\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "print(type(a))\n", 151 | "\n", 152 | "print(type(b))" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 8, 158 | "id": "eee6e94c", 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "cmuiain\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "s = \"communication\"\n", 171 | "# 0123456789\n", 172 | "\n", 173 | "print(s[::2]) # start : end : steps" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 9, 179 | "id": "25ad503f", 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "noitacinummoc\n" 187 | ] 188 | } 189 | ], 190 | "source": [ 191 | "print(s[::-1])" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": 10, 197 | "id": "d94c6eef", 198 | "metadata": {}, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "niaiumc\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "print(s[::-2])" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 11, 215 | "id": "c948db64", 216 | "metadata": {}, 217 | "outputs": [ 218 | { 219 | "data": { 220 | "text/plain": [ 221 | "'communication'" 222 | ] 223 | }, 224 | "execution_count": 11, 225 | "metadata": {}, 226 | "output_type": "execute_result" 227 | } 228 | ], 229 | "source": [ 230 | "s # immutable" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 12, 236 | "id": "9e6ac8ef", 237 | "metadata": {}, 238 | "outputs": [ 239 | { 240 | "name": "stdout", 241 | "output_type": "stream", 242 | "text": [ 243 | "umm\n" 244 | ] 245 | } 246 | ], 247 | "source": [ 248 | "print(s[4:1:-1])" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 13, 254 | "id": "67be0a62", 255 | "metadata": {}, 256 | "outputs": [ 257 | { 258 | "name": "stdout", 259 | "output_type": "stream", 260 | "text": [ 261 | "ommunication\n" 262 | ] 263 | } 264 | ], 265 | "source": [ 266 | "print(s[1:55:])" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 14, 272 | "id": "fbac2f2e", 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "noitacinumm\n" 280 | ] 281 | } 282 | ], 283 | "source": [ 284 | "print(s[55:1:-1])" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 15, 290 | "id": "d17f3cac", 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "ename": "ValueError", 295 | "evalue": "slice step cannot be zero", 296 | "output_type": "error", 297 | "traceback": [ 298 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 299 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 300 | "Input \u001b[1;32mIn [15]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43ms\u001b[49m\u001b[43m[\u001b[49m\u001b[43m:\u001b[49m\u001b[43m:\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m)\n", 301 | "\u001b[1;31mValueError\u001b[0m: slice step cannot be zero" 302 | ] 303 | } 304 | ], 305 | "source": [ 306 | "print(s[::0])" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": null, 312 | "id": "9923dbec", 313 | "metadata": {}, 314 | "outputs": [], 315 | "source": [] 316 | } 317 | ], 318 | "metadata": { 319 | "kernelspec": { 320 | "display_name": "Python 3 (ipykernel)", 321 | "language": "python", 322 | "name": "python3" 323 | }, 324 | "language_info": { 325 | "codemirror_mode": { 326 | "name": "ipython", 327 | "version": 3 328 | }, 329 | "file_extension": ".py", 330 | "mimetype": "text/x-python", 331 | "name": "python", 332 | "nbconvert_exporter": "python", 333 | "pygments_lexer": "ipython3", 334 | "version": "3.9.12" 335 | } 336 | }, 337 | "nbformat": 4, 338 | "nbformat_minor": 5 339 | } 340 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/6_String/30_String Basics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "911057cd", 6 | "metadata": {}, 7 | "source": [ 8 | "# String Basics\n", 9 | "\n", 10 | "Watch the video at 1.5x speed for better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "7dc8e3fc", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "indore\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "s = 'indore'\n", 30 | "\n", 31 | "print(s)\n", 32 | "\n", 33 | "print(type(s))" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 2, 39 | "id": "13adf4e4", 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "A\n", 47 | "\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "s = 'A'\n", 53 | "\n", 54 | "print(s)\n", 55 | "\n", 56 | "print(type(s))" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 3, 62 | "id": "14908ec3", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "M\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "s = 'Machine'\n", 75 | "# 0123456\n", 76 | "\n", 77 | "print(s[0])" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 4, 83 | "id": "4a4484bd", 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "e\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "print(s[6])" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 5, 101 | "id": "4891138f", 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "ename": "IndexError", 106 | "evalue": "string index out of range", 107 | "output_type": "error", 108 | "traceback": [ 109 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 110 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 111 | "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43ms\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m9\u001b[39;49m\u001b[43m]\u001b[49m)\n", 112 | "\u001b[1;31mIndexError\u001b[0m: string index out of range" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "print(s[9])" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 6, 123 | "id": "36ccf2fb", 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "e\n" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "# -1\n", 136 | "s = 'Machine'\n", 137 | "# 0123456\n", 138 | "\n", 139 | "print(s[-1])" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 7, 145 | "id": "2250b4a0", 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "name": "stdout", 150 | "output_type": "stream", 151 | "text": [ 152 | "Learning\n", 153 | "\n" 154 | ] 155 | } 156 | ], 157 | "source": [ 158 | "s = \"Learning\"\n", 159 | "\n", 160 | "print(s)\n", 161 | "\n", 162 | "print(type(s))" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 8, 168 | "id": "e9f72b61", 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "name": "stdout", 173 | "output_type": "stream", 174 | "text": [ 175 | "\"Hello\"\n" 176 | ] 177 | } 178 | ], 179 | "source": [ 180 | "s = '\"Hello\"'\n", 181 | "\n", 182 | "print(s)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 9, 188 | "id": "471ab27c", 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "name": "stdout", 193 | "output_type": "stream", 194 | "text": [ 195 | "\"\n" 196 | ] 197 | } 198 | ], 199 | "source": [ 200 | "print(s[0])" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 11, 206 | "id": "62cb0500", 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "ename": "SyntaxError", 211 | "evalue": "invalid syntax (1513794406.py, line 1)", 212 | "output_type": "error", 213 | "traceback": [ 214 | "\u001b[1;36m Input \u001b[1;32mIn [11]\u001b[1;36m\u001b[0m\n\u001b[1;33m s = 'It's'\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "s = 'It's'\n", 220 | "\n", 221 | "print(s)" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 12, 227 | "id": "64a13a49", 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "It's\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "s = \"It's\"\n", 240 | "print(s)" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 13, 246 | "id": "22400c72", 247 | "metadata": {}, 248 | "outputs": [ 249 | { 250 | "name": "stdout", 251 | "output_type": "stream", 252 | "text": [ 253 | "\n", 254 | "\n" 255 | ] 256 | } 257 | ], 258 | "source": [ 259 | "# empty strings\n", 260 | "\n", 261 | "s = ''\n", 262 | "\n", 263 | "print(s)\n", 264 | "\n", 265 | "print(type(s))" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": null, 271 | "id": "9376728a", 272 | "metadata": {}, 273 | "outputs": [], 274 | "source": [ 275 | "s = \"ABC\"" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": 14, 281 | "id": "365c660a", 282 | "metadata": {}, 283 | "outputs": [ 284 | { 285 | "name": "stdout", 286 | "output_type": "stream", 287 | "text": [ 288 | "True\n" 289 | ] 290 | } 291 | ], 292 | "source": [ 293 | "print(bool(\" \"))" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": 15, 299 | "id": "3f932473", 300 | "metadata": {}, 301 | "outputs": [ 302 | { 303 | "name": "stdout", 304 | "output_type": "stream", 305 | "text": [ 306 | "False\n" 307 | ] 308 | } 309 | ], 310 | "source": [ 311 | "print(bool(''))" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 16, 317 | "id": "8fb5ec71", 318 | "metadata": {}, 319 | "outputs": [ 320 | { 321 | "name": "stdout", 322 | "output_type": "stream", 323 | "text": [ 324 | "True\n" 325 | ] 326 | } 327 | ], 328 | "source": [ 329 | "print(bool(1))" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": 17, 335 | "id": "0e3ec645", 336 | "metadata": {}, 337 | "outputs": [ 338 | { 339 | "name": "stdout", 340 | "output_type": "stream", 341 | "text": [ 342 | "False\n" 343 | ] 344 | } 345 | ], 346 | "source": [ 347 | "print(bool(0))" 348 | ] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "execution_count": 18, 353 | "id": "c6e6f358", 354 | "metadata": {}, 355 | "outputs": [ 356 | { 357 | "name": "stdout", 358 | "output_type": "stream", 359 | "text": [ 360 | "ABCD\n" 361 | ] 362 | } 363 | ], 364 | "source": [ 365 | "# concatenation\n", 366 | "\n", 367 | "s = \"A\" + \"BCD\"\n", 368 | "\n", 369 | "print(s)" 370 | ] 371 | }, 372 | { 373 | "cell_type": "code", 374 | "execution_count": 19, 375 | "id": "34df52e9", 376 | "metadata": {}, 377 | "outputs": [ 378 | { 379 | "name": "stdout", 380 | "output_type": "stream", 381 | "text": [ 382 | "A BCD\n" 383 | ] 384 | } 385 | ], 386 | "source": [ 387 | "s = \"A \" + \"BCD\"\n", 388 | "\n", 389 | "print(s)" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "execution_count": null, 395 | "id": "87794b70", 396 | "metadata": {}, 397 | "outputs": [], 398 | "source": [ 399 | "# immutable objects\n", 400 | "\n", 401 | "s = 'India'\n", 402 | "\n", 403 | "s[3] = \"A\"\n" 404 | ] 405 | } 406 | ], 407 | "metadata": { 408 | "kernelspec": { 409 | "display_name": "Python 3 (ipykernel)", 410 | "language": "python", 411 | "name": "python3" 412 | }, 413 | "language_info": { 414 | "codemirror_mode": { 415 | "name": "ipython", 416 | "version": 3 417 | }, 418 | "file_extension": ".py", 419 | "mimetype": "text/x-python", 420 | "name": "python", 421 | "nbconvert_exporter": "python", 422 | "pygments_lexer": "ipython3", 423 | "version": "3.9.12" 424 | } 425 | }, 426 | "nbformat": 4, 427 | "nbformat_minor": 5 428 | } 429 | -------------------------------------------------------------------------------- /Chapter 1 - starting point to become a python warrior/6_String/31_String Slicing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a4def3de", 6 | "metadata": {}, 7 | "source": [ 8 | "# String Slicing\n", 9 | "\n", 10 | "Watch the video at 1.5x speed for better experience." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "9bebb0c0", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "c\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "s = \"communication\"\n", 29 | "# 0123456789\n", 30 | "\n", 31 | "print(s[0])" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "id": "145895a6", 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "comm\n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "print(s[0:4])" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 3, 55 | "id": "7a5d2488", 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "mmunic\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "print(s[2:8])" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 4, 73 | "id": "a808f7ff", 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "name": "stdout", 78 | "output_type": "stream", 79 | "text": [ 80 | "\n" 81 | ] 82 | } 83 | ], 84 | "source": [ 85 | "print(s[4:1])" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 5, 91 | "id": "4a47cde8", 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "data": { 96 | "text/plain": [ 97 | "''" 98 | ] 99 | }, 100 | "execution_count": 5, 101 | "metadata": {}, 102 | "output_type": "execute_result" 103 | } 104 | ], 105 | "source": [ 106 | "s[4:1]" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 6, 112 | "id": "516f7dcd", 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "True\n", 120 | "False\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "a = \" \" # -> 32\n", 126 | "\n", 127 | "b = \"\"\n", 128 | "\n", 129 | "print(bool(a))\n", 130 | "\n", 131 | "print(bool(b))" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 7, 137 | "id": "f1dd6671", 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "name": "stdout", 142 | "output_type": "stream", 143 | "text": [ 144 | "\n", 145 | "\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "print(type(a))\n", 151 | "\n", 152 | "print(type(b))" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 8, 158 | "id": "eee6e94c", 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "cmuiain\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "s = \"communication\"\n", 171 | "# 0123456789\n", 172 | "\n", 173 | "print(s[::2]) # start : end : steps" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 9, 179 | "id": "25ad503f", 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "noitacinummoc\n" 187 | ] 188 | } 189 | ], 190 | "source": [ 191 | "print(s[::-1])" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": 10, 197 | "id": "d94c6eef", 198 | "metadata": {}, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "niaiumc\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "print(s[::-2])" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 11, 215 | "id": "c948db64", 216 | "metadata": {}, 217 | "outputs": [ 218 | { 219 | "data": { 220 | "text/plain": [ 221 | "'communication'" 222 | ] 223 | }, 224 | "execution_count": 11, 225 | "metadata": {}, 226 | "output_type": "execute_result" 227 | } 228 | ], 229 | "source": [ 230 | "s # immutable" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 12, 236 | "id": "9e6ac8ef", 237 | "metadata": {}, 238 | "outputs": [ 239 | { 240 | "name": "stdout", 241 | "output_type": "stream", 242 | "text": [ 243 | "umm\n" 244 | ] 245 | } 246 | ], 247 | "source": [ 248 | "print(s[4:1:-1])" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 13, 254 | "id": "67be0a62", 255 | "metadata": {}, 256 | "outputs": [ 257 | { 258 | "name": "stdout", 259 | "output_type": "stream", 260 | "text": [ 261 | "ommunication\n" 262 | ] 263 | } 264 | ], 265 | "source": [ 266 | "print(s[1:55:])" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 14, 272 | "id": "fbac2f2e", 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "noitacinumm\n" 280 | ] 281 | } 282 | ], 283 | "source": [ 284 | "print(s[55:1:-1])" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 15, 290 | "id": "d17f3cac", 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "ename": "ValueError", 295 | "evalue": "slice step cannot be zero", 296 | "output_type": "error", 297 | "traceback": [ 298 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 299 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 300 | "Input \u001b[1;32mIn [15]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43ms\u001b[49m\u001b[43m[\u001b[49m\u001b[43m:\u001b[49m\u001b[43m:\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m)\n", 301 | "\u001b[1;31mValueError\u001b[0m: slice step cannot be zero" 302 | ] 303 | } 304 | ], 305 | "source": [ 306 | "print(s[::0])" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": null, 312 | "id": "9923dbec", 313 | "metadata": {}, 314 | "outputs": [], 315 | "source": [] 316 | } 317 | ], 318 | "metadata": { 319 | "kernelspec": { 320 | "display_name": "Python 3 (ipykernel)", 321 | "language": "python", 322 | "name": "python3" 323 | }, 324 | "language_info": { 325 | "codemirror_mode": { 326 | "name": "ipython", 327 | "version": 3 328 | }, 329 | "file_extension": ".py", 330 | "mimetype": "text/x-python", 331 | "name": "python", 332 | "nbconvert_exporter": "python", 333 | "pygments_lexer": "ipython3", 334 | "version": "3.9.12" 335 | } 336 | }, 337 | "nbformat": 4, 338 | "nbformat_minor": 5 339 | } 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-For-Beginners --------------------------------------------------------------------------------