|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "6fccf90b", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "Enter a word: lovely\n", |
| 14 | + "Middle letter ---> e\n" |
| 15 | + ] |
| 16 | + } |
| 17 | + ], |
| 18 | + "source": [ |
| 19 | + "#To find the middle letter of a string\n", |
| 20 | + "string = input(\"Enter a word: \")\n", |
| 21 | + "length = len(string)\n", |
| 22 | + "print(\"Middle letter --->\",string[length//2])" |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "code", |
| 27 | + "execution_count": 2, |
| 28 | + "id": "b9a560b1", |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [ |
| 31 | + { |
| 32 | + "name": "stdout", |
| 33 | + "output_type": "stream", |
| 34 | + "text": [ |
| 35 | + "Enter a list:ram sita snek Snek\n", |
| 36 | + "Yes\n" |
| 37 | + ] |
| 38 | + } |
| 39 | + ], |
| 40 | + "source": [ |
| 41 | + "#To check if \"Snek\" is present in the list\n", |
| 42 | + "l = list(map(str,input(\"Enter a list:\").split()))\n", |
| 43 | + "if 'Snek' in l:\n", |
| 44 | + " print(\"Yes\")\n", |
| 45 | + "else:\n", |
| 46 | + " print(\"NO\")" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": 3, |
| 52 | + "id": "d3f6c7bd", |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [ |
| 55 | + { |
| 56 | + "name": "stdout", |
| 57 | + "output_type": "stream", |
| 58 | + "text": [ |
| 59 | + "A Number? 9\n", |
| 60 | + "2 4 6 8 " |
| 61 | + ] |
| 62 | + } |
| 63 | + ], |
| 64 | + "source": [ |
| 65 | + "#To print even integers from 1 to N\n", |
| 66 | + "val = int(input(\"A Number? \"))\n", |
| 67 | + "for i in range(1,val+1):\n", |
| 68 | + " if(i%2==0):\n", |
| 69 | + " print(i,end= \" \")" |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + "cell_type": "code", |
| 74 | + "execution_count": 5, |
| 75 | + "id": "bf6d647e", |
| 76 | + "metadata": {}, |
| 77 | + "outputs": [ |
| 78 | + { |
| 79 | + "name": "stdout", |
| 80 | + "output_type": "stream", |
| 81 | + "text": [ |
| 82 | + "goa 4\n", |
| 83 | + "gggg oooo aaaa " |
| 84 | + ] |
| 85 | + } |
| 86 | + ], |
| 87 | + "source": [ |
| 88 | + "#To print a repeatable string\n", |
| 89 | + "str,o=input().split()\n", |
| 90 | + "o = int(o)\n", |
| 91 | + "for i in range(len(str)):\n", |
| 92 | + " print(str[i]*o,end=\" \")" |
| 93 | + ] |
| 94 | + }, |
| 95 | + { |
| 96 | + "cell_type": "code", |
| 97 | + "execution_count": 6, |
| 98 | + "id": "e39e09fd", |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [ |
| 101 | + { |
| 102 | + "name": "stdout", |
| 103 | + "output_type": "stream", |
| 104 | + "text": [ |
| 105 | + "2 -7 0\n", |
| 106 | + "-7\n", |
| 107 | + "-7\n" |
| 108 | + ] |
| 109 | + } |
| 110 | + ], |
| 111 | + "source": [ |
| 112 | + "#To find the smallest element out of three\n", |
| 113 | + "a,b,c=input().split()\n", |
| 114 | + "print(a if(a<b and a<c) else b if(b<c) else c)\n", |
| 115 | + "print(min(a,b,c))" |
| 116 | + ] |
| 117 | + }, |
| 118 | + { |
| 119 | + "cell_type": "code", |
| 120 | + "execution_count": 7, |
| 121 | + "id": "a505f612", |
| 122 | + "metadata": {}, |
| 123 | + "outputs": [ |
| 124 | + { |
| 125 | + "name": "stdout", |
| 126 | + "output_type": "stream", |
| 127 | + "text": [ |
| 128 | + "jkl\n", |
| 129 | + "is\n", |
| 130 | + "\n", |
| 131 | + "# Fine\n" |
| 132 | + ] |
| 133 | + } |
| 134 | + ], |
| 135 | + "source": [ |
| 136 | + "#Triple quotes enclosed string values (spans multiple lines including new)\n", |
| 137 | + "k = '''jkl\n", |
| 138 | + "is\n", |
| 139 | + "\n", |
| 140 | + "# Fine'''\n", |
| 141 | + "print(k)" |
| 142 | + ] |
| 143 | + }, |
| 144 | + { |
| 145 | + "cell_type": "code", |
| 146 | + "execution_count": 8, |
| 147 | + "id": "b23dcf75", |
| 148 | + "metadata": {}, |
| 149 | + "outputs": [ |
| 150 | + { |
| 151 | + "name": "stdout", |
| 152 | + "output_type": "stream", |
| 153 | + "text": [ |
| 154 | + "jk45\n", |
| 155 | + "False\n" |
| 156 | + ] |
| 157 | + } |
| 158 | + ], |
| 159 | + "source": [ |
| 160 | + "# To check if the input contains only digits\n", |
| 161 | + "k = input()\n", |
| 162 | + "print(k.isdigit())" |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + "cell_type": "code", |
| 167 | + "execution_count": 9, |
| 168 | + "id": "539f23c8", |
| 169 | + "metadata": {}, |
| 170 | + "outputs": [ |
| 171 | + { |
| 172 | + "name": "stdout", |
| 173 | + "output_type": "stream", |
| 174 | + "text": [ |
| 175 | + "Positive vibes only....🤩\n", |
| 176 | + "oiievbsol..🤩\n" |
| 177 | + ] |
| 178 | + } |
| 179 | + ], |
| 180 | + "source": [ |
| 181 | + "# To print Even position character\n", |
| 182 | + "a = input()\n", |
| 183 | + "print(a[1::2])" |
| 184 | + ] |
| 185 | + }, |
| 186 | + { |
| 187 | + "cell_type": "code", |
| 188 | + "execution_count": 10, |
| 189 | + "id": "14e0b0eb", |
| 190 | + "metadata": {}, |
| 191 | + "outputs": [ |
| 192 | + { |
| 193 | + "name": "stdout", |
| 194 | + "output_type": "stream", |
| 195 | + "text": [ |
| 196 | + "once in blue moon\n", |
| 197 | + "ONCE\n", |
| 198 | + "Once\n" |
| 199 | + ] |
| 200 | + } |
| 201 | + ], |
| 202 | + "source": [ |
| 203 | + "# To toggle the case of 1st word\n", |
| 204 | + "b = input().split(\" \")\n", |
| 205 | + "l = b[0]\n", |
| 206 | + "print((b[0]).swapcase())\n", |
| 207 | + "print(l[0].swapcase(),l[1:],sep=\"\")" |
| 208 | + ] |
| 209 | + }, |
| 210 | + { |
| 211 | + "cell_type": "code", |
| 212 | + "execution_count": 11, |
| 213 | + "id": "4120a270", |
| 214 | + "metadata": {}, |
| 215 | + "outputs": [ |
| 216 | + { |
| 217 | + "name": "stdout", |
| 218 | + "output_type": "stream", |
| 219 | + "text": [ |
| 220 | + "2 3 444 5 6 77777 88 9 0\n", |
| 221 | + "0 88 6 444 2\n" |
| 222 | + ] |
| 223 | + } |
| 224 | + ], |
| 225 | + "source": [ |
| 226 | + "# To print only even nubers in reverse order in their occurance\n", |
| 227 | + "list1 = list(map(int,input().split()))\n", |
| 228 | + "new_list=[]\n", |
| 229 | + "for i in range(0,len(list1)):\n", |
| 230 | + " if(list1[i]%2==0):\n", |
| 231 | + " new_list.append(list1[i]) \n", |
| 232 | + " \n", |
| 233 | + "print(*new_list[::-1])" |
| 234 | + ] |
| 235 | + }, |
| 236 | + { |
| 237 | + "cell_type": "code", |
| 238 | + "execution_count": 12, |
| 239 | + "id": "87ba5513", |
| 240 | + "metadata": {}, |
| 241 | + "outputs": [ |
| 242 | + { |
| 243 | + "name": "stdout", |
| 244 | + "output_type": "stream", |
| 245 | + "text": [ |
| 246 | + "Enter a string : hello , am I making sense🤔❔\n", |
| 247 | + "Yep\n" |
| 248 | + ] |
| 249 | + } |
| 250 | + ], |
| 251 | + "source": [ |
| 252 | + "#To check if first word starts with \"hello\"\n", |
| 253 | + "string = input(\"Enter a string : \")\n", |
| 254 | + "if string.startswith(\"hello\"):\n", |
| 255 | + " print(\"Yep\")\n", |
| 256 | + "else:\n", |
| 257 | + " print(\"Oh no!\")" |
| 258 | + ] |
| 259 | + }, |
| 260 | + { |
| 261 | + "cell_type": "code", |
| 262 | + "execution_count": 13, |
| 263 | + "id": "a5170fc9", |
| 264 | + "metadata": {}, |
| 265 | + "outputs": [ |
| 266 | + { |
| 267 | + "name": "stdout", |
| 268 | + "output_type": "stream", |
| 269 | + "text": [ |
| 270 | + "[10, 97, 68]\n" |
| 271 | + ] |
| 272 | + } |
| 273 | + ], |
| 274 | + "source": [ |
| 275 | + "#To delete a element in a list\n", |
| 276 | + "li = [10,8,97,68]\n", |
| 277 | + "del li[1]\n", |
| 278 | + "print(li)" |
| 279 | + ] |
| 280 | + }, |
| 281 | + { |
| 282 | + "cell_type": "code", |
| 283 | + "execution_count": 15, |
| 284 | + "id": "538cfac5", |
| 285 | + "metadata": {}, |
| 286 | + "outputs": [ |
| 287 | + { |
| 288 | + "name": "stdout", |
| 289 | + "output_type": "stream", |
| 290 | + "text": [ |
| 291 | + "['a', 'e', 'i', '0', 5, 'klo']\n" |
| 292 | + ] |
| 293 | + } |
| 294 | + ], |
| 295 | + "source": [ |
| 296 | + "#Appending list\n", |
| 297 | + "l1 = ['a','e','i','0']\n", |
| 298 | + "l1 +=[5,\"klo\"]\n", |
| 299 | + "print(l1)" |
| 300 | + ] |
| 301 | + }, |
| 302 | + { |
| 303 | + "cell_type": "code", |
| 304 | + "execution_count": 16, |
| 305 | + "id": "bc8e85a8", |
| 306 | + "metadata": {}, |
| 307 | + "outputs": [ |
| 308 | + { |
| 309 | + "name": "stdout", |
| 310 | + "output_type": "stream", |
| 311 | + "text": [ |
| 312 | + "pineapple\n", |
| 313 | + "0\n", |
| 314 | + "1\n" |
| 315 | + ] |
| 316 | + } |
| 317 | + ], |
| 318 | + "source": [ |
| 319 | + "#Finding the maximum\n", |
| 320 | + "fruits = ('custard apple','orange','pineapple','cherry',)\n", |
| 321 | + "print(max(fruits))\n", |
| 322 | + "print(fruits.count('Orange'))\n", |
| 323 | + "print(fruits.count('orange'))\n" |
| 324 | + ] |
| 325 | + }, |
| 326 | + { |
| 327 | + "cell_type": "code", |
| 328 | + "execution_count": 17, |
| 329 | + "id": "e2e81f8c", |
| 330 | + "metadata": {}, |
| 331 | + "outputs": [ |
| 332 | + { |
| 333 | + "name": "stdout", |
| 334 | + "output_type": "stream", |
| 335 | + "text": [ |
| 336 | + "The new list : [1, 3, 7, 4, 5, 6]\n", |
| 337 | + "After sorting [1, 3, 4, 5, 6, 7]\n" |
| 338 | + ] |
| 339 | + } |
| 340 | + ], |
| 341 | + "source": [ |
| 342 | + "#Inserting elements\n", |
| 343 | + "no = [1,3,4,5,6]\n", |
| 344 | + "no.insert(2,7)\n", |
| 345 | + "print(\"The new list : \",no)\n", |
| 346 | + "print(\"After sorting\",sorted(no))" |
| 347 | + ] |
| 348 | + } |
| 349 | + ], |
| 350 | + "metadata": { |
| 351 | + "kernelspec": { |
| 352 | + "display_name": "Python 3 (ipykernel)", |
| 353 | + "language": "python", |
| 354 | + "name": "python3" |
| 355 | + }, |
| 356 | + "language_info": { |
| 357 | + "codemirror_mode": { |
| 358 | + "name": "ipython", |
| 359 | + "version": 3 |
| 360 | + }, |
| 361 | + "file_extension": ".py", |
| 362 | + "mimetype": "text/x-python", |
| 363 | + "name": "python", |
| 364 | + "nbconvert_exporter": "python", |
| 365 | + "pygments_lexer": "ipython3", |
| 366 | + "version": "3.10.2" |
| 367 | + } |
| 368 | + }, |
| 369 | + "nbformat": 4, |
| 370 | + "nbformat_minor": 5 |
| 371 | +} |
0 commit comments