|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "### Task 1\n", |
| 8 | + "\n", |
| 9 | + "Write a python program that prints a square of size N using + where N will be given as input.\n", |
| 10 | + "\n", |
| 11 | + "**Sample Input**\n", |
| 12 | + "5\n", |
| 13 | + "\n", |
| 14 | + "**Sample Output**<br>\n", |
| 15 | + "+++++<br>\n", |
| 16 | + "+++++<br>\n", |
| 17 | + "+++++<br>\n", |
| 18 | + "+++++<br>\n", |
| 19 | + "+++++<br>\n" |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + "cell_type": "code", |
| 24 | + "execution_count": null, |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [], |
| 27 | + "source": [] |
| 28 | + }, |
| 29 | + { |
| 30 | + "cell_type": "markdown", |
| 31 | + "metadata": {}, |
| 32 | + "source": [ |
| 33 | + "### Task 2\n", |
| 34 | + "\n", |
| 35 | + "Write a python program that prints a rectangle of size M (height) and N(length) using + where M,N will be given as input.\n", |
| 36 | + "\n", |
| 37 | + "**Sample Input**\n", |
| 38 | + "3,8\n", |
| 39 | + "\n", |
| 40 | + "**Sample Output**<br>\n", |
| 41 | + "++++++++<br>\n", |
| 42 | + "++++++++<br>\n", |
| 43 | + "++++++++<br>\n" |
| 44 | + ] |
| 45 | + }, |
| 46 | + { |
| 47 | + "cell_type": "code", |
| 48 | + "execution_count": null, |
| 49 | + "metadata": {}, |
| 50 | + "outputs": [], |
| 51 | + "source": [] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "markdown", |
| 55 | + "metadata": {}, |
| 56 | + "source": [ |
| 57 | + "### Task 3\n", |
| 58 | + "\n", |
| 59 | + "Write a python program that prints a right angled triangle of height N using + where N will be given as input.\n", |
| 60 | + "\n", |
| 61 | + "**Sample Input**\n", |
| 62 | + "4\n", |
| 63 | + "\n", |
| 64 | + "**Sample Output**<br>\n", |
| 65 | + "+<br>\n", |
| 66 | + "++<br>\n", |
| 67 | + "+++<br>\n", |
| 68 | + "++++<br>\n" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "code", |
| 73 | + "execution_count": 8, |
| 74 | + "metadata": {}, |
| 75 | + "outputs": [ |
| 76 | + { |
| 77 | + "name": "stdout", |
| 78 | + "output_type": "stream", |
| 79 | + "text": [ |
| 80 | + "Enter a number4\n", |
| 81 | + "+\n", |
| 82 | + "++\n", |
| 83 | + "+++\n", |
| 84 | + "++++\n" |
| 85 | + ] |
| 86 | + } |
| 87 | + ], |
| 88 | + "source": [ |
| 89 | + "x=int(input(\"Enter a number\"))\n", |
| 90 | + "for j in range(x):\n", |
| 91 | + " for y in range(j+1):\n", |
| 92 | + " print(\"+\",end=\"\")\n", |
| 93 | + " print(\"\")\n" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "markdown", |
| 98 | + "metadata": {}, |
| 99 | + "source": [ |
| 100 | + "### Task 4\n", |
| 101 | + "\n", |
| 102 | + "Write a python program that prints a square of size N using incrementing numbers where N will be given as input.\n", |
| 103 | + "\n", |
| 104 | + "**Sample Input**\n", |
| 105 | + "5\n", |
| 106 | + "\n", |
| 107 | + "**Sample Output**<br>\n", |
| 108 | + "12345<br>\n", |
| 109 | + "12345<br>\n", |
| 110 | + "12345<br>\n", |
| 111 | + "12345<br>\n", |
| 112 | + "12345<br>\n", |
| 113 | + "\n" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "execution_count": 5, |
| 119 | + "metadata": {}, |
| 120 | + "outputs": [ |
| 121 | + { |
| 122 | + "name": "stdout", |
| 123 | + "output_type": "stream", |
| 124 | + "text": [ |
| 125 | + "Enter a number5\n", |
| 126 | + "12345\n", |
| 127 | + "12345\n", |
| 128 | + "12345\n", |
| 129 | + "12345\n", |
| 130 | + "12345\n" |
| 131 | + ] |
| 132 | + } |
| 133 | + ], |
| 134 | + "source": [ |
| 135 | + "x=int(input(\"Enter a number\"))\n", |
| 136 | + "for j in range(1,x+1):\n", |
| 137 | + " for y in range(1,x+1):\n", |
| 138 | + " print(y,end=\"\")\n", |
| 139 | + " print(\"\")\n" |
| 140 | + ] |
| 141 | + }, |
| 142 | + { |
| 143 | + "cell_type": "markdown", |
| 144 | + "metadata": {}, |
| 145 | + "source": [ |
| 146 | + "### Task 5\n", |
| 147 | + "\n", |
| 148 | + "Write a python program that prints a rectangle of size M (height) and N(length) using incrementing numbers where M,N will be given as input.\n", |
| 149 | + "\n", |
| 150 | + "**Sample Input**\n", |
| 151 | + "4,6\n", |
| 152 | + "\n", |
| 153 | + "**Sample Output**<br>\n", |
| 154 | + "123456<br>\n", |
| 155 | + "123456<br>\n", |
| 156 | + "123456<br>\n", |
| 157 | + "123456<br>\n" |
| 158 | + ] |
| 159 | + }, |
| 160 | + { |
| 161 | + "cell_type": "code", |
| 162 | + "execution_count": null, |
| 163 | + "metadata": {}, |
| 164 | + "outputs": [], |
| 165 | + "source": [] |
| 166 | + }, |
| 167 | + { |
| 168 | + "cell_type": "markdown", |
| 169 | + "metadata": {}, |
| 170 | + "source": [ |
| 171 | + "### Task 6\n", |
| 172 | + "\n", |
| 173 | + "Write a python program that prints a right angled triangle of height N using incrementing numbers where N will be given as input.\n", |
| 174 | + "\n", |
| 175 | + "**Sample Input**\n", |
| 176 | + "4\n", |
| 177 | + "\n", |
| 178 | + "**Sample Output**<br>\n", |
| 179 | + "1<br>\n", |
| 180 | + "12<br>\n", |
| 181 | + "123<br>\n", |
| 182 | + "1234<br>\n" |
| 183 | + ] |
| 184 | + }, |
| 185 | + { |
| 186 | + "cell_type": "code", |
| 187 | + "execution_count": 20, |
| 188 | + "metadata": {}, |
| 189 | + "outputs": [ |
| 190 | + { |
| 191 | + "name": "stdout", |
| 192 | + "output_type": "stream", |
| 193 | + "text": [ |
| 194 | + "Enter a number4\n", |
| 195 | + "1\n", |
| 196 | + "12\n", |
| 197 | + "123\n", |
| 198 | + "1234\n" |
| 199 | + ] |
| 200 | + } |
| 201 | + ], |
| 202 | + "source": [ |
| 203 | + "x=int(input(\"Enter a number\"))\n", |
| 204 | + "for j in range(1,x+1):\n", |
| 205 | + " for y in range(1,j+1):\n", |
| 206 | + " print(y,end=\"\")\n", |
| 207 | + " print(\"\")" |
| 208 | + ] |
| 209 | + }, |
| 210 | + { |
| 211 | + "cell_type": "markdown", |
| 212 | + "metadata": {}, |
| 213 | + "source": [ |
| 214 | + "### Task 7\n", |
| 215 | + "\n", |
| 216 | + "Write a python program that prints all the fibonacci number from 0 to N where N will be given. ***A Fibonacci number is a number which is the summation of its previous two fibonacci number. *** First two fibonacci number are 0 and 1. So the 3rd Fib will be 0+1=1, 4th Fib will be 1+1=2, 5th Fib will be 1+2=3 and so on.\n", |
| 217 | + "\n", |
| 218 | + "**Sample Input**<br>\n", |
| 219 | + "10\n", |
| 220 | + "\n", |
| 221 | + "**Sample Output**<br>\n", |
| 222 | + "0 1 1 2 3 5 8" |
| 223 | + ] |
| 224 | + }, |
| 225 | + { |
| 226 | + "cell_type": "code", |
| 227 | + "execution_count": 22, |
| 228 | + "metadata": {}, |
| 229 | + "outputs": [ |
| 230 | + { |
| 231 | + "name": "stdout", |
| 232 | + "output_type": "stream", |
| 233 | + "text": [ |
| 234 | + "Enter a number10\n", |
| 235 | + "0 1 1 2 3 5 8 " |
| 236 | + ] |
| 237 | + } |
| 238 | + ], |
| 239 | + "source": [ |
| 240 | + "n = int(input(\"Enter a number\"))\n", |
| 241 | + "y=0\n", |
| 242 | + "a = 0\n", |
| 243 | + "print(a,end=\" \")\n", |
| 244 | + "b = 1\n", |
| 245 | + "sum = a+b\n", |
| 246 | + "print(b,end=\" \")\n", |
| 247 | + "while sum<n:\n", |
| 248 | + "\n", |
| 249 | + " print(sum,end=\" \")\n", |
| 250 | + " a=b\n", |
| 251 | + " b=sum\n", |
| 252 | + " sum=a+b" |
| 253 | + ] |
| 254 | + }, |
| 255 | + { |
| 256 | + "cell_type": "markdown", |
| 257 | + "metadata": {}, |
| 258 | + "source": [ |
| 259 | + "### Task 8\n", |
| 260 | + "\n", |
| 261 | + "Write a python program that converts a Decimal Integer number to a Boolean Number. \n", |
| 262 | + "\n", |
| 263 | + "**A decimal can be converted to a binary number by keeping track of the remainders after each division of that number by 2. For example, to convert 10 to a binary number, we can follow the following approach**\n", |
| 264 | + "\n", |
| 265 | + "2/10 = 5 (Remainder 0) <br>2/5 = 2 (Remainder 1) \n", |
| 266 | + "<br>2/2 = 1 (Remainder 0) \n", |
| 267 | + "<br>2/1 = 0 (Remainder 1) \n", |
| 268 | + "\n", |
| 269 | + "Take the remainders from bottom to top, which is, 1010. Binary of 10 is 1010.\n", |
| 270 | + "\n", |
| 271 | + "**Sample Input** <br>\n", |
| 272 | + "10\n", |
| 273 | + "\n", |
| 274 | + "**Sample Output**<br>\n", |
| 275 | + "1010" |
| 276 | + ] |
| 277 | + }, |
| 278 | + { |
| 279 | + "cell_type": "code", |
| 280 | + "execution_count": null, |
| 281 | + "metadata": {}, |
| 282 | + "outputs": [], |
| 283 | + "source": [] |
| 284 | + }, |
| 285 | + { |
| 286 | + "cell_type": "markdown", |
| 287 | + "metadata": {}, |
| 288 | + "source": [ |
| 289 | + "### Task 9\n", |
| 290 | + "\n", |
| 291 | + "Write a python program that converts a Binary number to a Decimal Integer Number. \n", |
| 292 | + "\n", |
| 293 | + "**A binary number can be converted to its corresponding decimal number by multiplying each binary digit with a power of 2 where the power denotes the position of the binary digit**\n", |
| 294 | + "\n", |
| 295 | + "For example, to convert 1010, we can do this - $2^{3}$ x 1 + $2^{2}$ x 0 + $2^{1}$ x 1 + $2^{0}$ x 0 = 10\n", |
| 296 | + "\n", |
| 297 | + "\n", |
| 298 | + "**Sample Input** <br>\n", |
| 299 | + "1010\n", |
| 300 | + "\n", |
| 301 | + "**Sample Output** <br>\n", |
| 302 | + "10" |
| 303 | + ] |
| 304 | + }, |
| 305 | + { |
| 306 | + "cell_type": "code", |
| 307 | + "execution_count": null, |
| 308 | + "metadata": {}, |
| 309 | + "outputs": [], |
| 310 | + "source": [] |
| 311 | + }, |
| 312 | + { |
| 313 | + "cell_type": "markdown", |
| 314 | + "metadata": {}, |
| 315 | + "source": [ |
| 316 | + "### Task 10\n", |
| 317 | + "\n", |
| 318 | + "Write a python program that counts the total unique digits of a number. <br>\n", |
| 319 | + "*To solve this problem, the number can be converted to a string and then nested iterations can be done over the string*\n", |
| 320 | + "\n", |
| 321 | + "\n", |
| 322 | + "\n", |
| 323 | + "\n", |
| 324 | + "**Sample Input** <br>\n", |
| 325 | + "12233345\n", |
| 326 | + "\n", |
| 327 | + "**Sample Output** <br>\n", |
| 328 | + "5" |
| 329 | + ] |
| 330 | + }, |
| 331 | + { |
| 332 | + "cell_type": "code", |
| 333 | + "execution_count": null, |
| 334 | + "metadata": {}, |
| 335 | + "outputs": [], |
| 336 | + "source": [] |
| 337 | + } |
| 338 | + ], |
| 339 | + "metadata": { |
| 340 | + "kernelspec": { |
| 341 | + "display_name": "Python 3", |
| 342 | + "language": "python", |
| 343 | + "name": "python3" |
| 344 | + }, |
| 345 | + "language_info": { |
| 346 | + "codemirror_mode": { |
| 347 | + "name": "ipython", |
| 348 | + "version": 3 |
| 349 | + }, |
| 350 | + "file_extension": ".py", |
| 351 | + "mimetype": "text/x-python", |
| 352 | + "name": "python", |
| 353 | + "nbconvert_exporter": "python", |
| 354 | + "pygments_lexer": "ipython3", |
| 355 | + "version": "3.7.6" |
| 356 | + } |
| 357 | + }, |
| 358 | + "nbformat": 4, |
| 359 | + "nbformat_minor": 2 |
| 360 | +} |
0 commit comments