├── Assignment day 3 Solutions .ipynb ├── Day 1 NoteBook .ipynb ├── Day 2 - Assignments .ipynb ├── Day 2 NoteBook.ipynb ├── Day 3 Assignment .ipynb ├── Day 3 Python .ipynb ├── Day 5 Python FCS .ipynb ├── Day 6 Python - Errors & Exception Handling | Unit testing.ipynb ├── Errors & exceptions Handling .ipynb ├── FCS Silver Project- Tic Tac Toe - Ujjwal Mahajan.ipynb ├── OOPs.ipynb ├── README.md ├── SILVER PROJECT - Parth Patel.ipynb ├── TIC TAC TOE .ipynb ├── __pycache__ └── cap.cpython-37.pyc ├── assignment3.txt ├── cap.py ├── day 2 - piyush takale.ipynb ├── fcs.txt ├── fcs1.txt ├── letsupgrade.txt ├── simpletest.py ├── test_cap.py └── testfile /Assignment day 3 Solutions .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 3, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Enter your marks - 86\n" 13 | ] 14 | }, 15 | { 16 | "data": { 17 | "text/plain": [ 18 | "int" 19 | ] 20 | }, 21 | "execution_count": 3, 22 | "metadata": {}, 23 | "output_type": "execute_result" 24 | } 25 | ], 26 | "source": [ 27 | "# take an input -- \n", 28 | "\n", 29 | "marks = int(input(\"Enter your marks - \"))\n", 30 | "\n", 31 | "type(marks)" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 4, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "A\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "# Compare it with if elif and else \n", 49 | "\n", 50 | "\n", 51 | "if marks >= 85 :\n", 52 | " print(\"A\")\n", 53 | "elif marks >= 75 and marks<= 84:\n", 54 | " print(\"B\")\n", 55 | "elif marks >= 65 and marks<= 74:\n", 56 | " print(\"C\")\n", 57 | "elif marks >= 55 and marks<= 64:\n", 58 | " print(\"D\")\n", 59 | "elif marks >= 45 and marks<= 54:\n", 60 | " print(\"E\")\n", 61 | "else:\n", 62 | " print(\"Fail - Try again\")" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 32, 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "name": "stdout", 72 | "output_type": "stream", 73 | "text": [ 74 | "76\n" 75 | ] 76 | } 77 | ], 78 | "source": [ 79 | "# Guess Team India Score - \n", 80 | "\n", 81 | "#Step 1 - Genrate a computer score of Team India in between 1 to 250\n", 82 | "\n", 83 | "import random\n", 84 | "\n", 85 | "computer_gen_score = random.randint(1,250)\n", 86 | "\n", 87 | "print(computer_gen_score)" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 33, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "Enter ur guessing score - in between 1 to 250 - 85\n", 100 | "85\n" 101 | ] 102 | }, 103 | { 104 | "data": { 105 | "text/plain": [ 106 | "int" 107 | ] 108 | }, 109 | "execution_count": 33, 110 | "metadata": {}, 111 | "output_type": "execute_result" 112 | } 113 | ], 114 | "source": [ 115 | "#Step 2 - Take a input of the user - \n", 116 | "\n", 117 | "user_score = int(input(\"Enter ur guessing score - in between 1 to 250 - \"))\n", 118 | "\n", 119 | "print(user_score)\n", 120 | "type(user_score)\n" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 34, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "Ok to go ahead\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "# Step 3 is checking the number is in between 1 to 250 yes or no \n", 138 | "\n", 139 | "if user_score > 250 and user_score<1 :\n", 140 | " print(\"Reduce your expectation for 20-20 Cricket\")\n", 141 | "else:\n", 142 | " print(\"Ok to go ahead\")" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 35, 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "#Step 4 - Check the Comp. gen and User input and see if they are in the \n", 152 | "#matching range \n", 153 | "\n", 154 | "check_range = computer_gen_score - user_score\n", 155 | "\n", 156 | "check_range = abs(check_range)\n", 157 | "\n" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 36, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "you are true Team India Fan\n" 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "#step 5 - Check if the range_score is less than 10 and print accordingly \n", 175 | "\n", 176 | "if check_range <= 10 and check_range>=1:\n", 177 | " print(\"you are true Team India Fan\")\n", 178 | "else:\n", 179 | " print(\"You are not true Team India Fan\")" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [] 188 | } 189 | ], 190 | "metadata": { 191 | "kernelspec": { 192 | "display_name": "Python 3", 193 | "language": "python", 194 | "name": "python3" 195 | }, 196 | "language_info": { 197 | "codemirror_mode": { 198 | "name": "ipython", 199 | "version": 3 200 | }, 201 | "file_extension": ".py", 202 | "mimetype": "text/x-python", 203 | "name": "python", 204 | "nbconvert_exporter": "python", 205 | "pygments_lexer": "ipython3", 206 | "version": "3.7.4" 207 | } 208 | }, 209 | "nbformat": 4, 210 | "nbformat_minor": 2 211 | } 212 | -------------------------------------------------------------------------------- /Day 1 NoteBook .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#sai" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "# Integers shift + enter to run a cell " 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "a = 1" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "b = 2 " 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "c = 4 " 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "sume = a +b +c " 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "print(sume)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "#floating point \n", 73 | "\n", 74 | "\n", 75 | "d = 5.6 \n", 76 | "e = 7.8\n", 77 | "\n", 78 | "f = d +e \n", 79 | "\n", 80 | "print(f)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "# String \n", 90 | "\n", 91 | "classname = \"LetsUpgrade FCS\"\n", 92 | "\n", 93 | "my_name = \"Sai-nvrsettle\"\n", 94 | "\n", 95 | "print(classname)\n", 96 | "print(my_name)\n" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "#List \n", 106 | "\n", 107 | "\n", 108 | "# we have done is declaring differnt object types in the list,\n", 109 | "# so we can use it in long term with our programming \n", 110 | "\n", 111 | "lst = [\"sai\",1,4.5,[1,\"we have done it \",3]]\n", 112 | "\n", 113 | "print(lst)\n", 114 | "\n", 115 | "# if i have to print a specif element 3rd element of the list \n", 116 | "\n", 117 | "print(lst[2])\n", 118 | "\n", 119 | "#if i have to print a specifc element of 4th item \n", 120 | "\n", 121 | "print(lst[3][1])" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "# Assignment is - \n", 131 | "\n", 132 | "#try all the list by default function and send us the examples via \n", 133 | "#jyputer Notebook\n", 134 | "\n", 135 | "lst.append(\"i will get added to the end of list\")\n", 136 | "#it appends one object in the end\n", 137 | "\n", 138 | "lst.clear()\n", 139 | "#____ \n" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "print(lst)" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "#dict -\n", 158 | "\n", 159 | "\n", 160 | "dit = {\"Hitechsoiety \":\"saikiran\", \"bravellyhills\":\"faizal\", \"gokuldhan\": \"abhijeet\"}\n", 161 | "\n", 162 | "print(dit)\n", 163 | "\n", 164 | "print(\"\")\n", 165 | "\n", 166 | "print(dit.get(\"bravellyhills\"))\n", 167 | "\n", 168 | "print(\"\")\n", 169 | "\n", 170 | "print(dit.items())\n" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": null, 176 | "metadata": {}, 177 | "outputs": [], 178 | "source": [ 179 | "# sets\n", 180 | "\n", 181 | "st = {1,23,4,'a','b'}\n", 182 | "\n", 183 | "print(st)\n" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "# boolean\n", 193 | "\n", 194 | "t = True \n", 195 | "\n", 196 | "y = False\n", 197 | "\n", 198 | "print(t)\n", 199 | "print(y)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "# Tuples = \n", 209 | "\n", 210 | "tup = (5,6,7,8,9)" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": { 217 | "scrolled": true 218 | }, 219 | "outputs": [], 220 | "source": [ 221 | "print(tup)" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": null, 227 | "metadata": {}, 228 | "outputs": [], 229 | "source": [ 230 | "\n", 231 | "# Python code to create a file \n", 232 | "file = open('letsupgrade.txt','w') \n", 233 | "\n", 234 | "file.write(\"This is the write command \\n\") \n", 235 | "file.write(\"It allows us to write in a particular file\") \n", 236 | "\n", 237 | "\n", 238 | "file.close() " 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": null, 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [ 247 | "#varilable \n", 248 | "\n", 249 | "\n", 250 | "sai = 100 \n", 251 | "\n", 252 | "\n", 253 | "\n", 254 | "\n" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": null, 260 | "metadata": {}, 261 | "outputs": [], 262 | "source": [ 263 | "list = \"sai\"" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": null, 269 | "metadata": {}, 270 | "outputs": [], 271 | "source": [ 272 | "list" 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": 2, 278 | "metadata": {}, 279 | "outputs": [ 280 | { 281 | "data": { 282 | "text/plain": [ 283 | "list" 284 | ] 285 | }, 286 | "execution_count": 2, 287 | "metadata": {}, 288 | "output_type": "execute_result" 289 | } 290 | ], 291 | "source": [ 292 | "list" 293 | ] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": null, 298 | "metadata": {}, 299 | "outputs": [], 300 | "source": [ 301 | "# It gives u the variable type \n", 302 | "\n", 303 | "\n", 304 | "type()" 305 | ] 306 | }, 307 | { 308 | "cell_type": "code", 309 | "execution_count": null, 310 | "metadata": {}, 311 | "outputs": [], 312 | "source": [] 313 | } 314 | ], 315 | "metadata": { 316 | "kernelspec": { 317 | "display_name": "Python 3", 318 | "language": "python", 319 | "name": "python3" 320 | }, 321 | "language_info": { 322 | "codemirror_mode": { 323 | "name": "ipython", 324 | "version": 3 325 | }, 326 | "file_extension": ".py", 327 | "mimetype": "text/x-python", 328 | "name": "python", 329 | "nbconvert_exporter": "python", 330 | "pygments_lexer": "ipython3", 331 | "version": "3.7.4" 332 | } 333 | }, 334 | "nbformat": 4, 335 | "nbformat_minor": 2 336 | } 337 | -------------------------------------------------------------------------------- /Day 2 - Assignments .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#Assignment One - \n", 10 | "\n", 11 | "\n", 12 | "file = open(\"assignment3.txt\",'w')\n", 13 | "\n", 14 | "file.write(\"I love and live for FCS\")\n", 15 | "\n", 16 | "file.close()\n", 17 | "\n" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "file = open(\"assignment3.txt\",'r')\n", 27 | "\n", 28 | "print(file.read())\n", 29 | "\n", 30 | "file.close()" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "#assignment 2 - \n", 40 | "\n", 41 | "marks = int(input(\"Enter your marks - \"))\n", 42 | "\n", 43 | "if(marks >= 85):\n", 44 | " print(\"A\")\n", 45 | "elif (marks>=75 and marks <= 84):\n", 46 | " print(\"B\")\n", 47 | "elif (marks>=65 and marks <= 74):\n", 48 | " print(\"C\")\n", 49 | "elif (marks>=55 and marks <= 64):\n", 50 | " print(\"D\")\n", 51 | "elif (marks>=45 and marks <= 54):\n", 52 | " print(\"E\")\n", 53 | "else:\n", 54 | " print(\"Need imporvement\")\n" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "# Assigment 3 - \n", 64 | "#Generating computer Score module \n", 65 | "from random import randint \n", 66 | "\n", 67 | "print(\"Computer Generated Team India Cricket Score - \",randint(1,250))\n", 68 | "computer_generated_team_india_score = randint(1,250)\n", 69 | "\n", 70 | "#Guessing module --- \n", 71 | "user_input = int(input(\"enter your guess \"))\n", 72 | "\n", 73 | "#Checking weather the number is near by yes or no \n", 74 | "diffeence = abs(user_input - computer_generated_team_india_score) >10\n", 75 | "\n", 76 | "if ( diffeence <=10 and diffeence >=1):\n", 77 | " print(\"you are true indian fan\")\n", 78 | "else:\n", 79 | " print(\"You are far away bro\")\n" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "abs(100)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "# Assingment four -- \n", 98 | "\n", 99 | "# L, N, W, H\n", 100 | "# how many times u want to upload a Photo ? \n", 101 | "n = int(input(\"Enter number of chances you want a user to upload ?\"))\n", 102 | "\n", 103 | "#Enter the Lenght size \n", 104 | "l = int(input(\"Enter the min Lenght ?\"))\n", 105 | "\n", 106 | "curent_operation = 0\n", 107 | "while(curent_operation= l and w >=l):\n", 114 | " if(h==w):\n", 115 | " print(\"Accepted\")\n", 116 | " else:\n", 117 | " print(\"Crop it\")\n", 118 | " else:\n", 119 | " print(\"minimum photo size should be four - \", l )\n", 120 | " " 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 4, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "Enter the Command for ankit to move - h\n", 133 | "Enter valid input, L,R,U,D\n", 134 | "ankit is here - 0 0\n", 135 | "Enter the Command for ankit to move - l\n", 136 | "ankit is here - -1 0\n", 137 | "Enter the Command for ankit to move - l\n", 138 | "ankit is here - -2 0\n", 139 | "Enter the Command for ankit to move - l\n", 140 | "ankit is here - -3 0\n", 141 | "Enter the Command for ankit to move - l\n", 142 | "ankit is here - -4 0\n", 143 | "Enter the Command for ankit to move - u\n", 144 | "ankit is here - -4 1\n" 145 | ] 146 | } 147 | ], 148 | "source": [ 149 | "# Assignment 5 \n", 150 | "\n", 151 | "ankit_x = 0 \n", 152 | "ankit_y = 0 \n", 153 | "\n", 154 | "max_move = 0\n", 155 | "\n", 156 | "while(max_move <= 5):\n", 157 | " max_move += 1\n", 158 | " command = input(\"Enter the Command for ankit to move - \")\n", 159 | " command = command.lower()\n", 160 | " \n", 161 | " if(command == \"l\"):\n", 162 | " ankit_x += -1\n", 163 | " elif (command == \"r\"):\n", 164 | " ankit_x += +1\n", 165 | " elif (command == \"u\"):\n", 166 | " ankit_y += 1\n", 167 | " elif( command == \"d\"):\n", 168 | " ankit_y -= 1\n", 169 | " else: \n", 170 | " print(\"Enter valid input, L,R,U,D\")\n", 171 | " \n", 172 | " print(\"ankit is here - \", ankit_x, ankit_y)\n", 173 | " " 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": null, 179 | "metadata": {}, 180 | "outputs": [], 181 | "source": [ 182 | "\n", 183 | "\n", 184 | "\n", 185 | "\n" 186 | ] 187 | } 188 | ], 189 | "metadata": { 190 | "kernelspec": { 191 | "display_name": "Python 3", 192 | "language": "python", 193 | "name": "python3" 194 | }, 195 | "language_info": { 196 | "codemirror_mode": { 197 | "name": "ipython", 198 | "version": 3 199 | }, 200 | "file_extension": ".py", 201 | "mimetype": "text/x-python", 202 | "name": "python", 203 | "nbconvert_exporter": "python", 204 | "pygments_lexer": "ipython3", 205 | "version": "3.7.4" 206 | } 207 | }, 208 | "nbformat": 4, 209 | "nbformat_minor": 2 210 | } 211 | -------------------------------------------------------------------------------- /Day 2 NoteBook.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#file handling \n", 10 | "\n", 11 | "\n", 12 | "#Create a File \n", 13 | "\n", 14 | "\n", 15 | "file = open('fcs1.txt','w')\n", 16 | "\n", 17 | "file.write(\"Hey we are coding along Python Files \\n\")\n", 18 | "file.write(\"We are completing today File handling\")\n", 19 | "\n", 20 | "file.close()\n", 21 | "\n" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "# Open a file and print the output \n", 31 | "\n", 32 | "file = open('fcs.txt','r')\n", 33 | "\n", 34 | "data = file.read()\n", 35 | "\n", 36 | "print(data)\n", 37 | "\n", 38 | "file.close()" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "# Append a file and print it \n", 48 | "\n", 49 | "file = open('fcs.txt','a')\n", 50 | "\n", 51 | "file.write(\"\\n LetsUpgrade\")\n", 52 | "\n", 53 | "file.close()" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "with open(\"fcs.txt\") as file: \n", 63 | " data = file.read() \n", 64 | " print(data)\n" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "# Operators \n", 74 | "\n", 75 | "a = 10 \n", 76 | "b = 20 \n", 77 | "print(a==b)\n", 78 | "print(a!=b)\n", 79 | "print(ab)\n", 81 | "print(a<=b)\n", 82 | "print(a>=b)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [ 91 | "# Logical Comperison Operators - \n", 92 | "\n", 93 | "#AND, OR, NOT \n", 94 | "\n", 95 | "#AND \n", 96 | "\n", 97 | "a = 10 \n", 98 | "b = 9 \n", 99 | "c = 8 \n", 100 | "\n", 101 | "print ( a > b and a < c)\n", 102 | "\n", 103 | "#in and both the condistions should be true " 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "# Logical Comperison Operators - \n", 113 | "\n", 114 | "#OR \n", 115 | "\n", 116 | "a = 10 \n", 117 | "b = 9 \n", 118 | "c = 8 \n", 119 | "\n", 120 | "print ( a > b or a < c)\n", 121 | "\n", 122 | "#in OR any one of the condistions should be true " 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "# Logical Comperison Operators - \n", 132 | "\n", 133 | "#NOT \n", 134 | "\n", 135 | "a = 10 \n", 136 | "b = 9 \n", 137 | "c = 8 \n", 138 | "\n", 139 | "data = a > b and a < c\n", 140 | "print ( data )\n", 141 | "print ( not data)\n", 142 | "\n", 143 | "#in and both the condistions should be true " 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "metadata": {}, 150 | "outputs": [], 151 | "source": [ 152 | "# IF ELIF Else\n", 153 | "\n", 154 | "students = \"not live\"\n", 155 | "a = 1 \n", 156 | "\n", 157 | "if(students == \"live\"):\n", 158 | " print(\"Sai will teach\")\n", 159 | " print(\"sai will teach again\")\n", 160 | " \n", 161 | "elif (students == \"not live\"):\n", 162 | " print(\"Sai will not teach\")\n", 163 | " if (a == 1):\n", 164 | " print('ok we are inside one')\n", 165 | " \n", 166 | "else:\n", 167 | " print(\"Sai is lost\")\n", 168 | " " 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": null, 174 | "metadata": {}, 175 | "outputs": [], 176 | "source": [ 177 | "value = input(\"Enter something - \")\n", 178 | "\n", 179 | "print(value)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [ 188 | "# Loops - \n", 189 | "\n", 190 | "\n", 191 | "lst = [1,2,3,4,5,6,7,8,9,\"sai\"]\n", 192 | "\n", 193 | "for item in lst:\n", 194 | " print(item)" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": null, 200 | "metadata": {}, 201 | "outputs": [], 202 | "source": [ 203 | "string = \"Hey guys, I want to meet you all and teach\"\n", 204 | "\n", 205 | "for item in string:\n", 206 | " print(item)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": null, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "a = 1\n", 216 | "\n", 217 | "while(a < 10 ):\n", 218 | " print(a)\n", 219 | "# a = a + 1 \n", 220 | " \n", 221 | " a += 1\n" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": null, 227 | "metadata": {}, 228 | "outputs": [], 229 | "source": [ 230 | "# Python code to illustrate with()\n", 231 | "\n", 232 | "with open(\"fcs.txt\") as file: \n", 233 | " data = file.read() \n", 234 | " print(data)\n", 235 | "\n", 236 | " # do something with data \n" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": null, 242 | "metadata": {}, 243 | "outputs": [], 244 | "source": [ 245 | "file = open('fcs.txt','r')\n", 246 | "\n", 247 | "print(file.read())\n", 248 | "\n", 249 | "file.close()" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": null, 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "with open(\"fcs.txt\", \"r\") as file: \n", 259 | " data = file.readlines() \n", 260 | " print(data)\n", 261 | " \n", 262 | "print(\"\\n\")\n", 263 | "print(\"\\n\")\n", 264 | " \n", 265 | "for line in data:\n", 266 | " word = line.split() \n", 267 | " print(word)" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": 1, 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "sai\n", 280 | "sai\n", 281 | "sai\n", 282 | "sai\n", 283 | "sai\n", 284 | "sai\n", 285 | "sai\n", 286 | "sai\n", 287 | "sai\n", 288 | "sai\n" 289 | ] 290 | } 291 | ], 292 | "source": [ 293 | "i = 1;\n", 294 | "\n", 295 | "while(i<=10):\n", 296 | " i += 1\n", 297 | " print(\"sai\")" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 2, 303 | "metadata": {}, 304 | "outputs": [], 305 | "source": [ 306 | "lst = [1,2,3,4,5]" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 5, 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "name": "stdout", 316 | "output_type": "stream", 317 | "text": [ 318 | "Help on built-in function append:\n", 319 | "\n", 320 | "append(object, /) method of builtins.list instance\n", 321 | " Append object to the end of the list.\n", 322 | "\n" 323 | ] 324 | } 325 | ], 326 | "source": [ 327 | "help(lst.append)" 328 | ] 329 | }, 330 | { 331 | "cell_type": "code", 332 | "execution_count": 6, 333 | "metadata": {}, 334 | "outputs": [ 335 | { 336 | "name": "stdout", 337 | "output_type": "stream", 338 | "text": [ 339 | "Help on built-in function clear:\n", 340 | "\n", 341 | "clear() method of builtins.list instance\n", 342 | " Remove all items from list.\n", 343 | "\n" 344 | ] 345 | } 346 | ], 347 | "source": [ 348 | "help(lst.clear)" 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": 7, 354 | "metadata": {}, 355 | "outputs": [ 356 | { 357 | "name": "stdout", 358 | "output_type": "stream", 359 | "text": [ 360 | "Help on built-in function extend:\n", 361 | "\n", 362 | "extend(iterable, /) method of builtins.list instance\n", 363 | " Extend list by appending elements from the iterable.\n", 364 | "\n" 365 | ] 366 | } 367 | ], 368 | "source": [ 369 | "help(lst.extend)" 370 | ] 371 | }, 372 | { 373 | "cell_type": "code", 374 | "execution_count": 8, 375 | "metadata": {}, 376 | "outputs": [ 377 | { 378 | "name": "stdout", 379 | "output_type": "stream", 380 | "text": [ 381 | "Help on built-in function insert:\n", 382 | "\n", 383 | "insert(index, object, /) method of builtins.list instance\n", 384 | " Insert object before index.\n", 385 | "\n" 386 | ] 387 | } 388 | ], 389 | "source": [ 390 | "help(lst.insert)" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": null, 396 | "metadata": {}, 397 | "outputs": [], 398 | "source": [] 399 | } 400 | ], 401 | "metadata": { 402 | "kernelspec": { 403 | "display_name": "Python 3", 404 | "language": "python", 405 | "name": "python3" 406 | }, 407 | "language_info": { 408 | "codemirror_mode": { 409 | "name": "ipython", 410 | "version": 3 411 | }, 412 | "file_extension": ".py", 413 | "mimetype": "text/x-python", 414 | "name": "python", 415 | "nbconvert_exporter": "python", 416 | "pygments_lexer": "ipython3", 417 | "version": "3.7.4" 418 | } 419 | }, 420 | "nbformat": 4, 421 | "nbformat_minor": 2 422 | } 423 | -------------------------------------------------------------------------------- /Day 3 Assignment .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 49, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#Input module \n", 10 | "def input_Module():\n", 11 | " lst = []\n", 12 | " i = 1\n", 13 | " while(i<=8): \n", 14 | " temp = int(input(\"Enter Element \"))\n", 15 | " lst.append(temp)\n", 16 | " i += 1\n", 17 | " return lst\n", 18 | " \n" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 5, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "Enter Element 1\n", 31 | "Enter Element 1\n", 32 | "Enter Element 5\n", 33 | "Enter Element 2\n", 34 | "Enter Element 3\n", 35 | "Enter Element 4\n", 36 | "Enter Element 5\n", 37 | "Enter Element 6\n", 38 | "[1, 1, 5, 2, 3, 4, 5, 6]\n" 39 | ] 40 | } 41 | ], 42 | "source": [ 43 | "input_Module()" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 43, 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "name": "stdout", 53 | "output_type": "stream", 54 | "text": [ 55 | "[1, 5]\n", 56 | "[1, 5]\n", 57 | "its gone\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "lst1 = [1, 5, 2, 1, 4, 5, 6,1]\n", 63 | "\n", 64 | "sub_lst = [1,1,5]\n", 65 | "\n", 66 | "i =0\n", 67 | "while(i<=8):\n", 68 | " if (len(sub_lst)>0 and lst1[i] == sub_lst[0]):\n", 69 | " sub_lst.pop(0)\n", 70 | " print(sub_lst)\n", 71 | " else:\n", 72 | " break\n", 73 | " i +=1\n", 74 | "\n", 75 | "print(sub_lst)\n", 76 | "\n", 77 | "if(len(sub_lst) == 0):\n", 78 | " print(\"its a match\")\n", 79 | "else:\n", 80 | " print(\"its gone\")" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 45, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "def check_the_sub_lst(lst):\n", 90 | " sub_lst = [1,1,5]\n", 91 | " for i in range(0,8):\n", 92 | " if(lst[i] == sub_lst[0]):\n", 93 | " sub_lst.pop(0)\n", 94 | " if(len(sub_lst) == 0):\n", 95 | " break\n", 96 | " if(len(sub_lst) == 0 ):\n", 97 | " return \"its a match\"\n", 98 | " else:\n", 99 | " return \"its gone\"" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 54, 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "name": "stdout", 109 | "output_type": "stream", 110 | "text": [ 111 | "Enter Element 1\n", 112 | "Enter Element 1\n", 113 | "Enter Element 2\n", 114 | "Enter Element 2\n", 115 | "Enter Element 2\n", 116 | "Enter Element 2\n", 117 | "Enter Element 2\n", 118 | "Enter Element 2\n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | "its gone\n" 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "#Main code \n", 128 | "\n", 129 | "new_lst = input_Module()\n", 130 | "print(\" \")\n", 131 | "print(\" \")\n", 132 | "print(\" \")\n", 133 | "soultion = check_the_sub_lst(new_lst)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 57, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "0\n", 146 | "1\n", 147 | "2\n", 148 | "3\n", 149 | "4\n", 150 | "5\n", 151 | "6\n", 152 | "7\n", 153 | "8\n", 154 | "9\n" 155 | ] 156 | } 157 | ], 158 | "source": [ 159 | "# Normal Loop \n", 160 | "\n", 161 | "for i in range(0,10):\n", 162 | " print(i)" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 58, 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "name": "stdout", 172 | "output_type": "stream", 173 | "text": [ 174 | "0\n", 175 | "1\n", 176 | "2\n", 177 | "3\n", 178 | "4\n", 179 | "5\n" 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "# Break \n", 185 | "\n", 186 | "for i in range(0,10):\n", 187 | " print(i)\n", 188 | " if(i == 5):\n", 189 | " break" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 59, 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "name": "stdout", 199 | "output_type": "stream", 200 | "text": [ 201 | "0\n", 202 | "1\n", 203 | "2\n", 204 | "3\n", 205 | "4\n", 206 | "6\n", 207 | "7\n", 208 | "8\n", 209 | "9\n" 210 | ] 211 | } 212 | ], 213 | "source": [ 214 | "# Continue \n", 215 | "\n", 216 | "for i in range(0,10):\n", 217 | " if(i == 5):\n", 218 | " continue\n", 219 | " print(i)" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": 60, 225 | "metadata": {}, 226 | "outputs": [ 227 | { 228 | "name": "stdout", 229 | "output_type": "stream", 230 | "text": [ 231 | "0\n", 232 | "1\n", 233 | "2\n", 234 | "3\n", 235 | "4\n", 236 | "5\n", 237 | "6\n", 238 | "7\n", 239 | "8\n", 240 | "9\n" 241 | ] 242 | } 243 | ], 244 | "source": [ 245 | "# Pass \n", 246 | "\n", 247 | "for i in range(0,10):\n", 248 | " if(i == 5):\n", 249 | " pass\n", 250 | " print(i)" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 61, 256 | "metadata": {}, 257 | "outputs": [], 258 | "source": [ 259 | "def fun():\n", 260 | " pass" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 62, 266 | "metadata": {}, 267 | "outputs": [], 268 | "source": [ 269 | "fun()" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": null, 275 | "metadata": {}, 276 | "outputs": [], 277 | "source": [] 278 | } 279 | ], 280 | "metadata": { 281 | "kernelspec": { 282 | "display_name": "Python 3", 283 | "language": "python", 284 | "name": "python3" 285 | }, 286 | "language_info": { 287 | "codemirror_mode": { 288 | "name": "ipython", 289 | "version": 3 290 | }, 291 | "file_extension": ".py", 292 | "mimetype": "text/x-python", 293 | "name": "python", 294 | "nbconvert_exporter": "python", 295 | "pygments_lexer": "ipython3", 296 | "version": "3.7.4" 297 | } 298 | }, 299 | "nbformat": 4, 300 | "nbformat_minor": 2 301 | } 302 | -------------------------------------------------------------------------------- /Day 3 Python .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "def name_of_function():\n", 10 | " '''\n", 11 | " This function actually does only printing of hello\n", 12 | " '''\n", 13 | " \n", 14 | " print(\"Hello\")\n", 15 | " \n", 16 | " \n", 17 | " \n", 18 | "name_of_function()" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "type(name_of_function())" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "help(name_of_function)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "#Lets experiment with return keyword\n", 46 | "\n", 47 | "def addition(number1,number2):\n", 48 | " add = number1 + number2\n", 49 | " return add" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "my_Addition = addition(1,3)\n", 59 | "\n", 60 | "print(my_Addition)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "my_Addition = addition(100,9897)\n", 70 | "\n", 71 | "print(my_Addition)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "#Lets experiment with return keyword\n", 81 | "\n", 82 | "def addition(number1,number2):\n", 83 | " add = number1 + number2 \n", 84 | " return add\n", 85 | "\n", 86 | "\n", 87 | "#ur program \n", 88 | "num1 = int(input(\"My first Number \"))\n", 89 | "num2 = int(input(\"My second Number\"))\n", 90 | "\n", 91 | "sume = addition(num1,num2)\n", 92 | "\n", 93 | "print(sume)\n", 94 | "\n" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": null, 100 | "metadata": {}, 101 | "outputs": [], 102 | "source": [ 103 | "def check_odd_even(number_to_check):\n", 104 | " if (number_to_check % 2 == 0):\n", 105 | " return \"Even\"\n", 106 | " else: \n", 107 | " return \"Odd\"\n", 108 | " \n", 109 | " \n", 110 | "#ur program block - \n", 111 | "\n", 112 | "number = int(input(\"Enter your number for checking is it odd or even\"))\n", 113 | "\n", 114 | "print(check_odd_even(number))" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "40 / 3" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "40 % 3 " 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "39 /3 \n" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 2, 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "name": "stdout", 151 | "output_type": "stream", 152 | "text": [ 153 | "Enter ur Dgree cel45\n", 154 | "113.0\n", 155 | "Enter ur Dgree Far113\n", 156 | "45.0\n" 157 | ] 158 | } 159 | ], 160 | "source": [ 161 | "# converting degree celsius to defree farinate - \n", 162 | "\n", 163 | "#f = 9/5*c + 32 \n", 164 | "\n", 165 | "def convert_to_far(degree_cel):\n", 166 | " degree_fa = (9/5)*degree_cel + 32\n", 167 | " return degree_fa\n", 168 | "\n", 169 | "def convert_to_cel(degree_far):\n", 170 | " degree_ca = (degree_far -32)\n", 171 | " degree_ca = degree_ca* (5/9)\n", 172 | "\n", 173 | " return degree_ca\n", 174 | "\n", 175 | "#Ur prgromming block - \n", 176 | "\n", 177 | "\n", 178 | "cel = int(input(\"Enter ur Dgree cel\"))\n", 179 | "\n", 180 | "print(convert_to_far(cel))\n", 181 | " \n", 182 | " \n", 183 | "Far = int(input(\"Enter ur Dgree Far\"))\n", 184 | "\n", 185 | "print(convert_to_cel(Far))\n", 186 | " \n", 187 | " " 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 3, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "hello\n", 200 | "hi\n", 201 | "are understanding\n" 202 | ] 203 | } 204 | ], 205 | "source": [ 206 | "#*args && **kwargs \n", 207 | "\n", 208 | "def my_args (*args):\n", 209 | " for arg in args:\n", 210 | " print(arg)\n", 211 | "\n", 212 | "my_args(\"hello\",\"hi\",\"are understanding\")\n" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 13, 218 | "metadata": {}, 219 | "outputs": [ 220 | { 221 | "name": "stdout", 222 | "output_type": "stream", 223 | "text": [ 224 | "firstname sai\n", 225 | "lastname s\n", 226 | "email sai@itm.edu\n" 227 | ] 228 | } 229 | ], 230 | "source": [ 231 | "#**kwargs \n", 232 | "\n", 233 | "def my_kwargs(**kwargs):\n", 234 | " for key,value in kwargs.items():\n", 235 | " print(key,value)\n", 236 | " \n", 237 | "my_kwargs(firstname = \"sai\",lastname = \"s\",email = \"sai@itm.edu\")\n" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "metadata": {}, 244 | "outputs": [], 245 | "source": [] 246 | } 247 | ], 248 | "metadata": { 249 | "kernelspec": { 250 | "display_name": "Python 3", 251 | "language": "python", 252 | "name": "python3" 253 | }, 254 | "language_info": { 255 | "codemirror_mode": { 256 | "name": "ipython", 257 | "version": 3 258 | }, 259 | "file_extension": ".py", 260 | "mimetype": "text/x-python", 261 | "name": "python", 262 | "nbconvert_exporter": "python", 263 | "pygments_lexer": "ipython3", 264 | "version": "3.7.4" 265 | } 266 | }, 267 | "nbformat": 4, 268 | "nbformat_minor": 2 269 | } 270 | -------------------------------------------------------------------------------- /Day 5 Python FCS .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# MAP - \n", 10 | "\n", 11 | "\n", 12 | "def cube(x):\n", 13 | " return x * x * x" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 2, 19 | "metadata": {}, 20 | "outputs": [ 21 | { 22 | "data": { 23 | "text/plain": [ 24 | "27" 25 | ] 26 | }, 27 | "execution_count": 2, 28 | "metadata": {}, 29 | "output_type": "execute_result" 30 | } 31 | ], 32 | "source": [ 33 | "cube(3)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 4, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "[1, 8, 27, 64, 125, 216]" 45 | ] 46 | }, 47 | "execution_count": 4, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "lst = [1,2,3,4,5,6]\n", 54 | "\n", 55 | "list(map(cube,lst))" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 5, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "# Filter - \n", 65 | "\n", 66 | "def even_odd(x):\n", 67 | " return x%2 == 0 " 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 7, 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "True" 79 | ] 80 | }, 81 | "execution_count": 7, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "even_odd(2)" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 9, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "data": { 97 | "text/plain": [ 98 | "[2, 4, 6]" 99 | ] 100 | }, 101 | "execution_count": 9, 102 | "metadata": {}, 103 | "output_type": "execute_result" 104 | } 105 | ], 106 | "source": [ 107 | "list(filter(even_odd,lst))" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 10, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "# Lambda \n", 117 | "def cube(x):\n", 118 | " return x * x * x\n", 119 | "\n", 120 | "cube1 = lambda x : x * x * x\n" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 11, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "data": { 130 | "text/plain": [ 131 | "27" 132 | ] 133 | }, 134 | "execution_count": 11, 135 | "metadata": {}, 136 | "output_type": "execute_result" 137 | } 138 | ], 139 | "source": [ 140 | "cube1(3)" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 12, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "data": { 150 | "text/plain": [ 151 | "[1, 8, 27, 64, 125, 216]" 152 | ] 153 | }, 154 | "execution_count": 12, 155 | "metadata": {}, 156 | "output_type": "execute_result" 157 | } 158 | ], 159 | "source": [ 160 | "list(map(lambda x : x * x * x,lst))" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 13, 166 | "metadata": {}, 167 | "outputs": [ 168 | { 169 | "data": { 170 | "text/plain": [ 171 | "[2, 4, 6]" 172 | ] 173 | }, 174 | "execution_count": 13, 175 | "metadata": {}, 176 | "output_type": "execute_result" 177 | } 178 | ], 179 | "source": [ 180 | "list(filter(lambda x : x%2 == 0 ,lst))" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 15, 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "ename": "IndentationError", 190 | "evalue": "unindent does not match any outer indentation level (, line 7)", 191 | "output_type": "error", 192 | "traceback": [ 193 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m7\u001b[0m\n\u001b[0;31m self.param1 = param1\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unindent does not match any outer indentation level\n" 194 | ] 195 | } 196 | ], 197 | "source": [ 198 | "#Class in Python\n", 199 | "\n", 200 | "class NameOfClass():\n", 201 | "\t\n", 202 | "\n", 203 | " def __init__(self,param1,param2):\n", 204 | "\t\tself.param1 = param1\n", 205 | "\t\tself.param2 = param2\n", 206 | "\t\n", 207 | "\tdef some_method(self):\n", 208 | "\t\t# perform some action\n", 209 | "\t\tprint(self.param1)" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 22, 215 | "metadata": {}, 216 | "outputs": [], 217 | "source": [ 218 | "# Sample Class - \n", 219 | "\n", 220 | "class vipin():\n", 221 | " pass\n", 222 | "\n", 223 | "v = vipin()" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 23, 229 | "metadata": {}, 230 | "outputs": [ 231 | { 232 | "data": { 233 | "text/plain": [ 234 | "__main__.vipin" 235 | ] 236 | }, 237 | "execution_count": 23, 238 | "metadata": {}, 239 | "output_type": "execute_result" 240 | } 241 | ], 242 | "source": [ 243 | "type(v)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 60, 249 | "metadata": {}, 250 | "outputs": [], 251 | "source": [ 252 | "#cycle class \n", 253 | "\n", 254 | "class cycle():\n", 255 | " \n", 256 | " name = \"\"\n", 257 | " \n", 258 | " def __init__(self,name=\"madrock\"):\n", 259 | " self.name = name\n" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 58, 265 | "metadata": {}, 266 | "outputs": [], 267 | "source": [ 268 | "altas = cycle()" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 59, 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "data": { 278 | "text/plain": [ 279 | "'madrock'" 280 | ] 281 | }, 282 | "execution_count": 59, 283 | "metadata": {}, 284 | "output_type": "execute_result" 285 | } 286 | ], 287 | "source": [ 288 | "altas.name" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 51, 294 | "metadata": {}, 295 | "outputs": [], 296 | "source": [ 297 | "montainbike = cycle()" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 43, 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "data": { 307 | "text/plain": [ 308 | "'madrock'" 309 | ] 310 | }, 311 | "execution_count": 43, 312 | "metadata": {}, 313 | "output_type": "execute_result" 314 | } 315 | ], 316 | "source": [ 317 | "montainbike.name" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 74, 323 | "metadata": {}, 324 | "outputs": [], 325 | "source": [ 326 | "class movie():\n", 327 | " movie_name = \"\"\n", 328 | " releaseDate = \"\"\n", 329 | " actors = \"\"\n", 330 | " director = \"\"\n", 331 | " producers = \"\"\n", 332 | " IMBD_rating = 0\n", 333 | " budget = \"\"\n", 334 | " \n", 335 | " def __init__(self,movie_name, releaseDate, actors,director, producers,IMBD_rating, budget):\n", 336 | " self.movie_name = movie_name\n", 337 | " self.releaseDate = releaseDate\n", 338 | " self.actors = actors\n", 339 | " self.director = director\n", 340 | " self.producers = producers\n", 341 | " self.IMBD_rating = IMBD_rating\n", 342 | " self.budget = budget\n", 343 | " \n", 344 | " def getBasicsDetails(self):\n", 345 | " return {\"movie_name\":self.movie_name, \"IMBD_rating\":self.IMBD_rating}\n", 346 | " \n", 347 | " def getTheBudget(self):\n", 348 | " return self.budget\n", 349 | " \n", 350 | " def setActors(self,actors):\n", 351 | " self.actors = actors\n", 352 | " " 353 | ] 354 | }, 355 | { 356 | "cell_type": "code", 357 | "execution_count": 70, 358 | "metadata": {}, 359 | "outputs": [], 360 | "source": [ 361 | "harryPotter = movie(\"harry Potter - goblet of fire\", \"12-9-1999\",\"Dainel Radcliff\",\"Some director\" ,\"You All\", 8.9,\"150 CR\")" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": 71, 367 | "metadata": {}, 368 | "outputs": [ 369 | { 370 | "data": { 371 | "text/plain": [ 372 | "{'movie_name': 'harry Potter - goblet of fire', 'IMBD_rating': 8.9}" 373 | ] 374 | }, 375 | "execution_count": 71, 376 | "metadata": {}, 377 | "output_type": "execute_result" 378 | } 379 | ], 380 | "source": [ 381 | "harryPotter.getBasicsDetails()" 382 | ] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "execution_count": 72, 387 | "metadata": {}, 388 | "outputs": [], 389 | "source": [ 390 | "harryPotter.setActors(\"Dainel and You Guys\")" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": 73, 396 | "metadata": {}, 397 | "outputs": [ 398 | { 399 | "data": { 400 | "text/plain": [ 401 | "'Dainel and You Guys'" 402 | ] 403 | }, 404 | "execution_count": 73, 405 | "metadata": {}, 406 | "output_type": "execute_result" 407 | } 408 | ], 409 | "source": [ 410 | "harryPotter.actors" 411 | ] 412 | }, 413 | { 414 | "cell_type": "markdown", 415 | "metadata": {}, 416 | "source": [ 417 | "# Inheritance " 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": 75, 423 | "metadata": {}, 424 | "outputs": [], 425 | "source": [ 426 | "#Base Class \n", 427 | "class Dog:\n", 428 | " def __init__ (self,name):\n", 429 | " self.name = name\n", 430 | " print(self.name +\" Dog got created\")\n", 431 | " \n", 432 | " def talk(self):\n", 433 | " return self.name + ' Says Bow Bow'\n", 434 | " \n", 435 | "\n", 436 | "#Dereived Class 1\n", 437 | "class Doberman(Dog):\n", 438 | " def __init__(self):\n", 439 | " Dog.__init__(self,'doberman')\n", 440 | " print(\"Doberman Got Created\")\n", 441 | " \n", 442 | " def drink(self):\n", 443 | " print(\"Doberman Drinks Proiten Shake !\")\n", 444 | " \n", 445 | " def heigh(self):\n", 446 | " print(\" Minimum height is 1 Meter\")\n", 447 | " \n", 448 | "#Dereived Class 2\n", 449 | "class pug(Dog):\n", 450 | " def __init__(self):\n", 451 | " Dog.__init__(self,'pug')\n", 452 | " print(\"Pugg Got Created\")\n", 453 | " \n", 454 | " def drink(self):\n", 455 | " print(\"Pugg Drinks Water !\")\n", 456 | " \n", 457 | " def lenght(self):\n", 458 | " print(\"Pugg lenght is - 0.5 meter\")" 459 | ] 460 | }, 461 | { 462 | "cell_type": "code", 463 | "execution_count": 76, 464 | "metadata": {}, 465 | "outputs": [ 466 | { 467 | "name": "stdout", 468 | "output_type": "stream", 469 | "text": [ 470 | "pug Dog got created\n", 471 | "Pugg Got Created\n" 472 | ] 473 | } 474 | ], 475 | "source": [ 476 | "sally = pug()" 477 | ] 478 | }, 479 | { 480 | "cell_type": "code", 481 | "execution_count": 80, 482 | "metadata": {}, 483 | "outputs": [ 484 | { 485 | "name": "stdout", 486 | "output_type": "stream", 487 | "text": [ 488 | "Pugg lenght is - 0.5 meter\n" 489 | ] 490 | } 491 | ], 492 | "source": [ 493 | "sally.lenght()" 494 | ] 495 | }, 496 | { 497 | "cell_type": "code", 498 | "execution_count": 81, 499 | "metadata": {}, 500 | "outputs": [ 501 | { 502 | "name": "stdout", 503 | "output_type": "stream", 504 | "text": [ 505 | "Pugg Drinks Water !\n" 506 | ] 507 | } 508 | ], 509 | "source": [ 510 | "sally.drink()" 511 | ] 512 | }, 513 | { 514 | "cell_type": "code", 515 | "execution_count": 82, 516 | "metadata": {}, 517 | "outputs": [ 518 | { 519 | "data": { 520 | "text/plain": [ 521 | "'pug Says Bow Bow'" 522 | ] 523 | }, 524 | "execution_count": 82, 525 | "metadata": {}, 526 | "output_type": "execute_result" 527 | } 528 | ], 529 | "source": [ 530 | "sally.talk()" 531 | ] 532 | }, 533 | { 534 | "cell_type": "code", 535 | "execution_count": 83, 536 | "metadata": {}, 537 | "outputs": [ 538 | { 539 | "name": "stdout", 540 | "output_type": "stream", 541 | "text": [ 542 | "doberman Dog got created\n", 543 | "Doberman Got Created\n" 544 | ] 545 | } 546 | ], 547 | "source": [ 548 | "Viz = Doberman()" 549 | ] 550 | }, 551 | { 552 | "cell_type": "code", 553 | "execution_count": 84, 554 | "metadata": {}, 555 | "outputs": [ 556 | { 557 | "data": { 558 | "text/plain": [ 559 | "'doberman Says Bow Bow'" 560 | ] 561 | }, 562 | "execution_count": 84, 563 | "metadata": {}, 564 | "output_type": "execute_result" 565 | } 566 | ], 567 | "source": [ 568 | "Viz.talk()" 569 | ] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "execution_count": 85, 574 | "metadata": {}, 575 | "outputs": [ 576 | { 577 | "name": "stdout", 578 | "output_type": "stream", 579 | "text": [ 580 | " Minimum height is 1 Meter\n" 581 | ] 582 | } 583 | ], 584 | "source": [ 585 | "Viz.heigh()" 586 | ] 587 | }, 588 | { 589 | "cell_type": "code", 590 | "execution_count": 87, 591 | "metadata": {}, 592 | "outputs": [ 593 | { 594 | "data": { 595 | "text/plain": [ 596 | "'doberman Says Bow Bow'" 597 | ] 598 | }, 599 | "execution_count": 87, 600 | "metadata": {}, 601 | "output_type": "execute_result" 602 | } 603 | ], 604 | "source": [ 605 | "Viz.talk()" 606 | ] 607 | }, 608 | { 609 | "cell_type": "code", 610 | "execution_count": null, 611 | "metadata": {}, 612 | "outputs": [], 613 | "source": [] 614 | } 615 | ], 616 | "metadata": { 617 | "kernelspec": { 618 | "display_name": "Python 3", 619 | "language": "python", 620 | "name": "python3" 621 | }, 622 | "language_info": { 623 | "codemirror_mode": { 624 | "name": "ipython", 625 | "version": 3 626 | }, 627 | "file_extension": ".py", 628 | "mimetype": "text/x-python", 629 | "name": "python", 630 | "nbconvert_exporter": "python", 631 | "pygments_lexer": "ipython3", 632 | "version": "3.7.4" 633 | } 634 | }, 635 | "nbformat": 4, 636 | "nbformat_minor": 2 637 | } 638 | -------------------------------------------------------------------------------- /Day 6 Python - Errors & Exception Handling | Unit testing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 6, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "There is an error\n", 13 | "hi\n" 14 | ] 15 | } 16 | ], 17 | "source": [ 18 | "try:\n", 19 | " print(10/0)\n", 20 | "except :\n", 21 | " print(\"There is an error\")\n", 22 | " \n", 23 | "print(\"hi\")" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 9, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "ename": "UnsupportedOperation", 33 | "evalue": "not writable", 34 | "output_type": "error", 35 | "traceback": [ 36 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 37 | "\u001b[0;31mUnsupportedOperation\u001b[0m Traceback (most recent call last)", 38 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mfile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"fcs.txt\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"r\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mfile\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Hey we are loving the class\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mfile\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 39 | "\u001b[0;31mUnsupportedOperation\u001b[0m: not writable" 40 | ] 41 | } 42 | ], 43 | "source": [ 44 | "file = open(\"fcs.txt\",\"r\")\n", 45 | "file.write(\"Hey we are loving the class\")\n", 46 | "file.close()" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 15, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "File mode is differnt\n", 59 | "I am Finally : I will print no matter who wins in my above brothers\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "try:\n", 65 | " file = open(\"fcs.txt\",\"r\")\n", 66 | " file.write(\"Hey we are loving the class\")\n", 67 | " file.close()\n", 68 | " print(\"try is working fine\")\n", 69 | " \n", 70 | "except OSError:\n", 71 | " print(\"File mode is differnt\")\n", 72 | "\n", 73 | "finally:\n", 74 | " print(\"I am Finally : I will print no matter who wins in my above brothers\")" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 39, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "Your Error - not writable\n", 87 | "I am Finally : I will print no matter who wins in my above brothers\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "try:\n", 93 | " file = open(\"fcs.txt\",\"r\")\n", 94 | " file.write(\"Hey we are loving the class\")\n", 95 | " file.close()\n", 96 | " print(\"try is working fine\")\n", 97 | " \n", 98 | "except Exception as e:\n", 99 | " print(\"Your Error - \", e)\n", 100 | "else:\n", 101 | " print(\"I am else block \")\n", 102 | "finally:\n", 103 | " print(\"I am Finally : I will print no matter who wins in my above brothers\")" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 25, 109 | "metadata": {}, 110 | "outputs": [ 111 | { 112 | "name": "stdout", 113 | "output_type": "stream", 114 | "text": [ 115 | "Ask everyone to submit there assignemnts\n", 116 | "Sai has to end the batch regardless of assignments submission\n" 117 | ] 118 | } 119 | ], 120 | "source": [ 121 | "try:\n", 122 | " raise NameError(\"Hi there\") # Raise Error \n", 123 | " print(\"if all have submitted there assignmets \")\n", 124 | " \n", 125 | "except :\n", 126 | " print(\"Ask everyone to submit there assignemnts\")\n", 127 | "else:\n", 128 | " print(\"please check them - logic realted to check the assignments\")\n", 129 | "finally:\n", 130 | " print(\"Sai has to end the batch regardless of assignments submission\")\n", 131 | " " 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 34, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "def ask_input():\n", 141 | " number = \"\"\n", 142 | " while True:\n", 143 | " try:\n", 144 | " number = int(input(\"Enter a Number - \"))\n", 145 | " except:\n", 146 | " print(\"Enter a Number not a Char\")\n", 147 | " continue\n", 148 | " else:\n", 149 | " print(\"Thank you we got a number\")\n", 150 | " break\n", 151 | " finally:\n", 152 | " print(\"Number = \",number)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 35, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "name": "stdout", 162 | "output_type": "stream", 163 | "text": [ 164 | "Enter a Number - r\n", 165 | "Enter a Number not a Char\n", 166 | "Number = \n", 167 | "Enter a Number - f\n", 168 | "Enter a Number not a Char\n", 169 | "Number = \n", 170 | "Enter a Number - 4\n", 171 | "Thank you we got a number\n", 172 | "Number = 4\n" 173 | ] 174 | } 175 | ], 176 | "source": [ 177 | "ask_input()" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "# Unit Testing" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": null, 190 | "metadata": {}, 191 | "outputs": [], 192 | "source": [] 193 | } 194 | ], 195 | "metadata": { 196 | "kernelspec": { 197 | "display_name": "Python 3", 198 | "language": "python", 199 | "name": "python3" 200 | }, 201 | "language_info": { 202 | "codemirror_mode": { 203 | "name": "ipython", 204 | "version": 3 205 | }, 206 | "file_extension": ".py", 207 | "mimetype": "text/x-python", 208 | "name": "python", 209 | "nbconvert_exporter": "python", 210 | "pygments_lexer": "ipython3", 211 | "version": "3.7.4" 212 | } 213 | }, 214 | "nbformat": 4, 215 | "nbformat_minor": 2 216 | } 217 | -------------------------------------------------------------------------------- /Errors & exceptions Handling .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 8, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Error : division by zero\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "try:\n", 18 | " print('Hello',5/0)\n", 19 | "except Exception as e :\n", 20 | " print('Error :',str(e))" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 9, 26 | "metadata": {}, 27 | "outputs": [ 28 | { 29 | "name": "stdout", 30 | "output_type": "stream", 31 | "text": [ 32 | "Content is getting Written\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "try:\n", 38 | " f = open('testfile','w')\n", 39 | " f.write('Test file')\n", 40 | "except IOError:\n", 41 | " print(\"File is giving IO Error\")\n", 42 | "else:\n", 43 | " print('Content is getting Written')" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 10, 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "name": "stdout", 53 | "output_type": "stream", 54 | "text": [ 55 | "File is giving IO Error\n" 56 | ] 57 | } 58 | ], 59 | "source": [ 60 | "try:\n", 61 | " f = open('testfile','r')\n", 62 | " f.write('Test file')\n", 63 | "except IOError:\n", 64 | " print(\"File is giving IO Error\")\n", 65 | "else:\n", 66 | " print('Content is getting Written')" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 11, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "File written and closed sucessfully\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "try:\n", 84 | " f = open ('testfile','w')\n", 85 | " f.write(\"This is awsm\")\n", 86 | " f.close()\n", 87 | "finally:\n", 88 | " print(\"File written and closed sucessfully\")" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 12, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "def askint():\n", 98 | " val = \"\"\n", 99 | " try:\n", 100 | " val = int(input(\"Enter an Integer value : \"))\n", 101 | " except Exception as e :\n", 102 | " print(\"Looks like you gave some other value than Integer \")\n", 103 | " else:\n", 104 | " print('Yep this is an Integer')\n", 105 | " finally:\n", 106 | " print('Hey Kiran! I am also a late comer like you :)')\n", 107 | " print(val)" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 13, 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "Enter an Integer value : 3\n", 120 | "Yep this is an Integer\n", 121 | "Hey Kiran! I am also a late comer like you :)\n", 122 | "3\n" 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "askint()" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "# Unit Testing " 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 14, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "name": "stdout", 144 | "output_type": "stream", 145 | "text": [ 146 | "Requirement already satisfied: pylint in /opt/anaconda3/lib/python3.7/site-packages (2.4.2)\n", 147 | "Requirement already satisfied: isort<5,>=4.2.5 in /opt/anaconda3/lib/python3.7/site-packages (from pylint) (4.3.21)\n", 148 | "Requirement already satisfied: mccabe<0.7,>=0.6 in /opt/anaconda3/lib/python3.7/site-packages (from pylint) (0.6.1)\n", 149 | "Requirement already satisfied: astroid<2.4,>=2.3.0 in /opt/anaconda3/lib/python3.7/site-packages (from pylint) (2.3.1)\n", 150 | "Requirement already satisfied: wrapt==1.11.* in /opt/anaconda3/lib/python3.7/site-packages (from astroid<2.4,>=2.3.0->pylint) (1.11.2)\n", 151 | "\u001b[33mWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')': /simple/typed-ast/\u001b[0m\n", 152 | "\u001b[33mWARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')': /simple/typed-ast/\u001b[0m\n", 153 | "Collecting typed-ast<1.5,>=1.4.0; implementation_name == \"cpython\" and python_version < \"3.8\"\n", 154 | " Downloading typed_ast-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl (223 kB)\n", 155 | "\u001b[K |████████████████████████████████| 223 kB 195 kB/s eta 0:00:01\n", 156 | "\u001b[?25hRequirement already satisfied: six==1.12 in /opt/anaconda3/lib/python3.7/site-packages (from astroid<2.4,>=2.3.0->pylint) (1.12.0)\n", 157 | "Requirement already satisfied: lazy-object-proxy==1.4.* in /opt/anaconda3/lib/python3.7/site-packages (from astroid<2.4,>=2.3.0->pylint) (1.4.2)\n", 158 | "Installing collected packages: typed-ast\n", 159 | "Successfully installed typed-ast-1.4.1\n" 160 | ] 161 | } 162 | ], 163 | "source": [ 164 | "! pip install pylint" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 15, 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "name": "stdout", 174 | "output_type": "stream", 175 | "text": [ 176 | "Writing simpletest.py\n" 177 | ] 178 | } 179 | ], 180 | "source": [ 181 | "%%writefile simpletest.py\n", 182 | "a=1\n", 183 | "b=2\n", 184 | "print(a)\n", 185 | "print(b)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 16, 191 | "metadata": {}, 192 | "outputs": [ 193 | { 194 | "name": "stdout", 195 | "output_type": "stream", 196 | "text": [ 197 | "************* Module simpletest\n", 198 | "simpletest.py:1:1: C0326: Exactly one space required around assignment\n", 199 | "a=1\n", 200 | " ^ (bad-whitespace)\n", 201 | "simpletest.py:2:1: C0326: Exactly one space required around assignment\n", 202 | "b=2\n", 203 | " ^ (bad-whitespace)\n", 204 | "simpletest.py:1:0: C0114: Missing module docstring (missing-module-docstring)\n", 205 | "simpletest.py:1:0: C0103: Constant name \"a\" doesn't conform to UPPER_CASE naming style (invalid-name)\n", 206 | "simpletest.py:2:0: C0103: Constant name \"b\" doesn't conform to UPPER_CASE naming style (invalid-name)\n", 207 | "\n", 208 | "------------------------------------\n", 209 | "Your code has been rated at -2.50/10\n", 210 | "\n" 211 | ] 212 | } 213 | ], 214 | "source": [ 215 | "! pylint simpletest.py" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": 33, 221 | "metadata": {}, 222 | "outputs": [ 223 | { 224 | "name": "stdout", 225 | "output_type": "stream", 226 | "text": [ 227 | "Overwriting simpletest1.py\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "%%writefile simpletest1.py\n", 233 | "'''\n", 234 | "A very own test file for python\n", 235 | "'''\n", 236 | "\n", 237 | "def myfun():\n", 238 | " '''\n", 239 | " An extremly idiotic Function in Python\n", 240 | " '''\n", 241 | " first = 1\n", 242 | " second = 2\n", 243 | " print(first)\n", 244 | " print(second)\n", 245 | "\n", 246 | "myfun()" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 34, 252 | "metadata": {}, 253 | "outputs": [ 254 | { 255 | "name": "stdout", 256 | "output_type": "stream", 257 | "text": [ 258 | "\n", 259 | "-------------------------------------------------------------------\n", 260 | "\n", 261 | "Your code has been rated at 10.00/10 (previous run: 6.67/10, +3.33)\n", 262 | "\n", 263 | "\n", 264 | "\n" 265 | ] 266 | } 267 | ], 268 | "source": [ 269 | "! pylint simpletest1.py" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 19, 275 | "metadata": {}, 276 | "outputs": [], 277 | "source": [ 278 | "##UnitTesting \n", 279 | "\n", 280 | "def cap_text(text):\n", 281 | " return text.title()" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 21, 287 | "metadata": {}, 288 | "outputs": [ 289 | { 290 | "data": { 291 | "text/plain": [ 292 | "'Python'" 293 | ] 294 | }, 295 | "execution_count": 21, 296 | "metadata": {}, 297 | "output_type": "execute_result" 298 | } 299 | ], 300 | "source": [ 301 | "cap_text('python')" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 6, 307 | "metadata": {}, 308 | "outputs": [ 309 | { 310 | "name": "stdout", 311 | "output_type": "stream", 312 | "text": [ 313 | "Overwriting cap.py\n" 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "%%writefile cap.py\n", 319 | "def cap_text(text):\n", 320 | " return text.title()" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 17, 326 | "metadata": {}, 327 | "outputs": [ 328 | { 329 | "name": "stdout", 330 | "output_type": "stream", 331 | "text": [ 332 | "Overwriting test_cap.py\n" 333 | ] 334 | } 335 | ], 336 | "source": [ 337 | "%%writefile test_cap.py\n", 338 | "\n", 339 | "import unittest\n", 340 | "import cap\n", 341 | "\n", 342 | "class TestCap(unittest.TestCase):\n", 343 | " \n", 344 | " def test_one_word(self):\n", 345 | " text = \"python\"\n", 346 | " result = cap.cap_text(text)\n", 347 | " self.assertEqual(result,'Python')\n", 348 | " \n", 349 | " def test_multiple_words(self):\n", 350 | " text = \"itm fcs\"\n", 351 | " result = cap.cap_text(text)\n", 352 | " self.assertEqual(result,'Itm Fcs')\n", 353 | " \n", 354 | "if __name__ == '__main__':\n", 355 | " unittest.main()" 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": 18, 361 | "metadata": {}, 362 | "outputs": [ 363 | { 364 | "name": "stdout", 365 | "output_type": "stream", 366 | "text": [ 367 | "..\r\n", 368 | "----------------------------------------------------------------------\r\n", 369 | "Ran 2 tests in 0.000s\r\n", 370 | "\r\n", 371 | "OK\r\n" 372 | ] 373 | } 374 | ], 375 | "source": [ 376 | "! python test_cap.py" 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": null, 382 | "metadata": {}, 383 | "outputs": [], 384 | "source": [] 385 | } 386 | ], 387 | "metadata": { 388 | "kernelspec": { 389 | "display_name": "Python 3", 390 | "language": "python", 391 | "name": "python3" 392 | }, 393 | "language_info": { 394 | "codemirror_mode": { 395 | "name": "ipython", 396 | "version": 3 397 | }, 398 | "file_extension": ".py", 399 | "mimetype": "text/x-python", 400 | "name": "python", 401 | "nbconvert_exporter": "python", 402 | "pygments_lexer": "ipython3", 403 | "version": "3.7.4" 404 | } 405 | }, 406 | "nbformat": 4, 407 | "nbformat_minor": 2 408 | } 409 | -------------------------------------------------------------------------------- /FCS Silver Project- Tic Tac Toe - Ujjwal Mahajan.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 43, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "from random import randint\n", 10 | "\n", 11 | "\n", 12 | "def display_board(board):\n", 13 | " for e in range(1, 18):\n", 14 | " if (e != 3) and (e != 6) and (e != 9) and (e != 12) and (e != 15):\n", 15 | " print(\" | | \")\n", 16 | " elif e == 3:\n", 17 | " print(f\" {board[1]} | {board[2]} | {board[3]} \")\n", 18 | " elif e == 9:\n", 19 | " print(f\" {board[4]} | {board[5]} | {board[6]} \")\n", 20 | " elif e == 6:\n", 21 | " print(\"======================================\")\n", 22 | " elif e == 12:\n", 23 | " print(\"======================================\")\n", 24 | " else:\n", 25 | " print(f\" {board[7]} | {board[8]} | {board[9]} \")" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 44, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "def player_marker_choose():\n", 35 | " choice = input('Player1 choose marker (X or O): ')\n", 36 | " if(choice.upper() != 'X') and (choice.upper() != 'O'):\n", 37 | " print(f'Invalid Input: {choice}')\n", 38 | " player_marker_choose()\n", 39 | " else:\n", 40 | " if choice.upper() == 'X':\n", 41 | " return 'X', 'O'\n", 42 | " else:\n", 43 | " return 'O', 'X'\n", 44 | "\n", 45 | "\n", 46 | "def who_goes_first():\n", 47 | " flip = randint(0, 1)\n", 48 | " if flip == 0:\n", 49 | " return 'Player1'\n", 50 | " else:\n", 51 | " return 'Player2'" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 45, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "def replay():\n", 61 | " # prompt to play again\n", 62 | " try:\n", 63 | " replay_reply = input('Hey!! Want to another round? (Yes / No): ')\n", 64 | " if replay_reply[0].lower() == 'y':\n", 65 | " print('\\n' * 50)\n", 66 | " tic_tac_toe_game()\n", 67 | " elif replay_reply[0].lower() == 'n':\n", 68 | " print('Game Over !!!')\n", 69 | " else:\n", 70 | " print('Please respond in Yes / No / Y / N')\n", 71 | " replay()\n", 72 | " except ValueError as v:\n", 73 | " print('Please check the value entered: ', v)\n", 74 | " replay()\n", 75 | " except Exception as e:\n", 76 | " print('ERROR: please check the exception and enter the value again ', e)\n", 77 | " replay()\n" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 46, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "def tic_tac_toe_game():\n", 87 | " test_board = ['#', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n", 88 | "\n", 89 | " # Winning Cases\n", 90 | " a = test_board[1] + test_board[2] + test_board[3]\n", 91 | " b = test_board[4] + test_board[5] + test_board[6]\n", 92 | " c = test_board[7] + test_board[8] + test_board[9]\n", 93 | " d = test_board[1] + test_board[4] + test_board[7]\n", 94 | " e = test_board[2] + test_board[5] + test_board[8]\n", 95 | " f = test_board[3] + test_board[6] + test_board[9]\n", 96 | " g = test_board[1] + test_board[5] + test_board[9]\n", 97 | " h = test_board[3] + test_board[5] + test_board[7]\n", 98 | "\n", 99 | " player1_marker, player2_marker = player_marker_choose()\n", 100 | " print(f'Marker for Player1 is {player1_marker}')\n", 101 | " print(f'Marker for Player2 is {player2_marker}')\n", 102 | " print(\"\")\n", 103 | "\n", 104 | " player_with_first_turn = who_goes_first()\n", 105 | " if player_with_first_turn == 'Player1':\n", 106 | " player_with_second_turn = 'Player2'\n", 107 | " else:\n", 108 | " player_with_second_turn = 'Player1'\n", 109 | "\n", 110 | " print(f'{player_with_first_turn} will go first')\n", 111 | " print(\"\")\n", 112 | "\n", 113 | " display_board(test_board)\n", 114 | " print(\"\")\n", 115 | "\n", 116 | " turn = 1\n", 117 | " try:\n", 118 | " while((a != 'XXX') and (b != 'XXX') and (c != 'XXX') and (d != 'XXX')\n", 119 | " and (e != 'XXX') and (f != 'XXX') and (g != 'XXX') and (h != 'XXX')\n", 120 | " and (a != 'OOO') and (b != 'OOO') and (c != 'OOO') and (d != 'OOO')\n", 121 | " and (e != 'OOO') and (f != 'OOO') and (g != 'OOO') and (h != 'OOO') and turn <= 9):\n", 122 | " try:\n", 123 | " position = int(input('Please enter the position at which you want to play: '))\n", 124 | " except ValueError as val:\n", 125 | " print('Please check the value entered: ', val)\n", 126 | " continue\n", 127 | " if position <= 9:\n", 128 | " if(test_board[position] != 'X') and (test_board[position] != 'O'):\n", 129 | " if(player1_marker == 'X' and player_with_first_turn == 'Player1') \\\n", 130 | " or (player2_marker == 'X' and player_with_first_turn == 'Player2'):\n", 131 | " if turn % 2 != 0:\n", 132 | " print(f'{player_with_first_turn} played X on position {position}')\n", 133 | " test_board[position] = 'X'\n", 134 | " turn = turn + 1\n", 135 | " else:\n", 136 | " print(f'{player_with_second_turn} played O on position {position}')\n", 137 | " test_board[position] = 'O'\n", 138 | " turn = turn + 1\n", 139 | " else:\n", 140 | " if turn % 2 != 0:\n", 141 | " print(f'{player_with_first_turn} played O on position {position}')\n", 142 | " test_board[position] = 'O'\n", 143 | " turn = turn + 1\n", 144 | " else:\n", 145 | " print(f'{player_with_second_turn} played X on position {position}')\n", 146 | " test_board[position] = 'X'\n", 147 | " turn = turn + 1\n", 148 | " else:\n", 149 | " print(f' Oops {test_board[position]} already occupied this spot, Try new position')\n", 150 | " else:\n", 151 | " print('Please enter value of Position between 1 to 9')\n", 152 | "\n", 153 | " # compute updated winning board\n", 154 | " a = test_board[1] + test_board[2] + test_board[3]\n", 155 | " b = test_board[4] + test_board[5] + test_board[6]\n", 156 | " c = test_board[7] + test_board[8] + test_board[9]\n", 157 | " d = test_board[1] + test_board[4] + test_board[7]\n", 158 | " e = test_board[2] + test_board[5] + test_board[8]\n", 159 | " f = test_board[3] + test_board[6] + test_board[9]\n", 160 | " g = test_board[1] + test_board[5] + test_board[9]\n", 161 | " h = test_board[3] + test_board[5] + test_board[7]\n", 162 | "\n", 163 | " display_board(test_board)\n", 164 | "\n", 165 | " else:\n", 166 | " if(player1_marker == 'X') and ((a == 'XXX') or (b == 'XXX') or (c == 'XXX') or (d == 'XXX')\n", 167 | " or (e == 'XXX') or (f == 'XXX') or (g == 'XXX') or (h == 'XXX')):\n", 168 | " print('Player1 Wins!!!, X was the symbol of the round')\n", 169 | " elif (player2_marker == 'X') and ((a == 'XXX') or (b == 'XXX') or (c == 'XXX') or (d == 'XXX')\n", 170 | " or (e == 'XXX') or (f == 'XXX') or (g == 'XXX') or (h == 'XXX')):\n", 171 | " print('Player2 Wins!!!, X was the symbol of the round')\n", 172 | " elif (player1_marker == 'O') and ((a == 'OOO') or (b == 'OOO') or (c == 'OOO') or (d == 'OOO')\n", 173 | " or (e == 'OOO') or (f == 'OOO') or (g == 'OOO') or (h == 'OOO')):\n", 174 | " print('Player1 Wins!!!, O was the symbol of the round')\n", 175 | " elif (player2_marker == 'O') and ((a == 'OOO') or (b == 'OOO') or (c == 'OOO') or (d == 'OOO')\n", 176 | " or (e == 'OOO') or (f == 'OOO') or (g == 'OOO') or (h == 'OOO')):\n", 177 | " print('Player2 Wins!!!, O was the symbol of the round')\n", 178 | " else:\n", 179 | " print('It was a Tie')\n", 180 | "\n", 181 | " except Exception as e:\n", 182 | " print('ERROR: please check the exception and enter the value again ', e)\n", 183 | " finally:\n", 184 | " replay()\n" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": null, 190 | "metadata": {}, 191 | "outputs": [], 192 | "source": [ 193 | "tic_tac_toe_game()" 194 | ] 195 | } 196 | ], 197 | "metadata": { 198 | "kernelspec": { 199 | "display_name": "Python 3", 200 | "language": "python", 201 | "name": "python3" 202 | }, 203 | "language_info": { 204 | "codemirror_mode": { 205 | "name": "ipython", 206 | "version": 3 207 | }, 208 | "file_extension": ".py", 209 | "mimetype": "text/x-python", 210 | "name": "python", 211 | "nbconvert_exporter": "python", 212 | "pygments_lexer": "ipython3", 213 | "version": "3.7.3" 214 | } 215 | }, 216 | "nbformat": 4, 217 | "nbformat_minor": 2 218 | } 219 | -------------------------------------------------------------------------------- /OOPs.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "lst = [1,2,3,4]" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 3, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "data": { 19 | "text/plain": [ 20 | "1" 21 | ] 22 | }, 23 | "execution_count": 3, 24 | "metadata": {}, 25 | "output_type": "execute_result" 26 | } 27 | ], 28 | "source": [ 29 | "lst.count(2)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 4, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "\n", 42 | "\n", 43 | "\n", 44 | "\n", 45 | "\n", 46 | "\n", 47 | "\n", 48 | "\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "print(type([]))\n", 54 | "print(type(1))\n", 55 | "print(type(1.1))\n", 56 | "print(type(\"Sai\"))\n", 57 | "print(type(True))\n", 58 | "print(type(()))\n", 59 | "print(type({}))\n", 60 | "print(type({'a','b'}))" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "#creating our class dummy \n", 70 | "\n", 71 | "class SampleDample:\n", 72 | " pass\n", 73 | "\n", 74 | "x = SampleDample()\n", 75 | "\n", 76 | "print(type(x))" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "class Tiger:\n", 86 | " def __init__(breed):\n", 87 | " self.breed = breed\n", 88 | " \n", 89 | "simba = Tiger(\"Bengal Tiger\")\n", 90 | "PK = Tiger(\"White Tiger\")" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "simba.breed" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "PK.breed" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "class Tiger:\n", 118 | " def __init__(self,breed1):\n", 119 | " self.breed = breed1\n", 120 | " \n", 121 | "simba = help(Tiger)\n", 122 | "PK = Tiger(\"White Tiger\")" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "simba.breed" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "PK.breed" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": null, 146 | "metadata": {}, 147 | "outputs": [], 148 | "source": [ 149 | "class Tiger:\n", 150 | " def __init__(self,breed,name):\n", 151 | " self.breed = breed\n", 152 | " self.name = name\n", 153 | " \n", 154 | "simba = Tiger(\"Bengal Tiger\",\"Simba\")\n", 155 | "PK = Tiger(\"White Tiger\",\"PK\")" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": null, 161 | "metadata": {}, 162 | "outputs": [], 163 | "source": [ 164 | "print(simba.name)\n", 165 | "print(simba.breed)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": {}, 171 | "source": [ 172 | "# Methods in Class \n" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "class Circle:\n", 182 | " \n", 183 | " pi = 3.14159\n", 184 | " \n", 185 | " def __init__(self,radius=1):\n", 186 | " self.radius = radius\n", 187 | " self.area = radius* radius * Circle.pi\n", 188 | " \n", 189 | " #Method for getting cirumfrence\n", 190 | " def getCircumference(self):\n", 191 | " return 2* self.pi * self.radius\n", 192 | " \n", 193 | " def setRadius(self,new_radius):\n", 194 | " self.radius = new_radius\n", 195 | " self.area = new_radius * new_radius * self.pi\n", 196 | " \n", 197 | "ayan = Circle()" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": null, 203 | "metadata": {}, 204 | "outputs": [], 205 | "source": [ 206 | "print(ayan.area)\n", 207 | "print(ayan.radius)\n", 208 | "print(ayan.getCircumference())\n", 209 | "print(ayan.setRadius(5))\n", 210 | "print(ayan.radius)\n", 211 | "print(ayan.radius)\n", 212 | "print(ayan.getCircumference())" 213 | ] 214 | }, 215 | { 216 | "cell_type": "markdown", 217 | "metadata": {}, 218 | "source": [ 219 | "# Inheritence " 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": null, 225 | "metadata": {}, 226 | "outputs": [], 227 | "source": [ 228 | "class dog:\n", 229 | " def __init__(self,name):\n", 230 | " self.name = name\n", 231 | " \n", 232 | " def talk(self):\n", 233 | " return self.name + ' Says boww boww'\n", 234 | "\n", 235 | "class cat:\n", 236 | " def __init__ (self,name):\n", 237 | " self.name = name\n", 238 | " print(self.name +\" Cat got created\")\n", 239 | " def talk(self):\n", 240 | " return self.name + ' Says Meeowww'\n", 241 | " \n", 242 | "class minu(cat):\n", 243 | " def __init__(self):\n", 244 | " cat.__init__(self,'minu')\n", 245 | " print(\"Minu Got Created\")\n", 246 | " \n", 247 | " def drink(self):\n", 248 | " print(\"Minu Drinks Milk !\")\n", 249 | " " 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": null, 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "m = minu()" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": null, 264 | "metadata": {}, 265 | "outputs": [], 266 | "source": [ 267 | "m.talk()" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": null, 273 | "metadata": {}, 274 | "outputs": [], 275 | "source": [ 276 | "m.drink()" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": null, 282 | "metadata": {}, 283 | "outputs": [], 284 | "source": [ 285 | "m.name" 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": {}, 291 | "source": [ 292 | "# Polymorphism " 293 | ] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": null, 298 | "metadata": {}, 299 | "outputs": [], 300 | "source": [ 301 | "class dog:\n", 302 | " def __init__(self,name):\n", 303 | " self.name = name\n", 304 | " \n", 305 | " def talk(self):\n", 306 | " return self.name + ' Says boww boww'\n", 307 | "\n", 308 | "class cat:\n", 309 | " def __init__ (self,name):\n", 310 | " self.name = name\n", 311 | " print(self.name +\" Cat got created\")\n", 312 | " def talk(self):\n", 313 | " return self.name + ' Says Meeowww'" 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": null, 319 | "metadata": {}, 320 | "outputs": [], 321 | "source": [ 322 | "huski = dog('huksi')\n", 323 | "minu = cat('minu')" 324 | ] 325 | }, 326 | { 327 | "cell_type": "code", 328 | "execution_count": null, 329 | "metadata": {}, 330 | "outputs": [], 331 | "source": [ 332 | "for pet in (huski,minu):\n", 333 | " print(pet.talk())" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": null, 339 | "metadata": {}, 340 | "outputs": [], 341 | "source": [ 342 | "\n", 343 | "print(huski.talk())\n", 344 | "print(minu.talk())" 345 | ] 346 | }, 347 | { 348 | "cell_type": "code", 349 | "execution_count": null, 350 | "metadata": {}, 351 | "outputs": [], 352 | "source": [ 353 | "class Animal():\n", 354 | " def __init__(self,name,breed):\n", 355 | " self.name = name \n", 356 | " self.breed = breed\n", 357 | " \n", 358 | " def speak(self):\n", 359 | " raise NotImplementedError(\"Sub Class Must Implement Speak Method\")\n", 360 | "\n", 361 | "class Elephant(Animal):\n", 362 | " def speak(self):\n", 363 | " return self.name + self.breed + ' Says D. Trump'\n", 364 | "\n", 365 | "\n", 366 | "class Horse(Animal):\n", 367 | " def speak(self):\n", 368 | " return self.name + self.breed+ ' Says Tarun'\n", 369 | " \n", 370 | "Jambo = Elephant('Jambo',' African Elephant')\n", 371 | "Alexandar = Horse('Alexandar',' percheron')\n", 372 | "\n", 373 | "print(Jambo.speak())\n", 374 | "print(Alexandar.speak())" 375 | ] 376 | }, 377 | { 378 | "cell_type": "code", 379 | "execution_count": null, 380 | "metadata": {}, 381 | "outputs": [], 382 | "source": [ 383 | "class Bank():\n", 384 | " def __init__(self,owner,balance=0):\n", 385 | " self.owner = owner\n", 386 | " self.balance = balance\n", 387 | " \n", 388 | " def deposit(self, balance):\n", 389 | " self.balance+= balance\n", 390 | " return self.balance\n", 391 | " \n", 392 | " def withdraw(self,balance):\n", 393 | " if self.balance >= balance:\n", 394 | " self.balance-=balance\n", 395 | " else:\n", 396 | " return \"Not Possible only \" + str(self.balance) + ' is avaliable'\n", 397 | " \n", 398 | " return self.balance\n", 399 | " " 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": null, 405 | "metadata": {}, 406 | "outputs": [], 407 | "source": [ 408 | "account1 = Bank('account1',100)\n" 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": null, 414 | "metadata": {}, 415 | "outputs": [], 416 | "source": [ 417 | "account1.deposit(1000)" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "metadata": {}, 424 | "outputs": [], 425 | "source": [ 426 | "account1.withdraw(700)" 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": null, 432 | "metadata": {}, 433 | "outputs": [], 434 | "source": [ 435 | "account1.owner" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": null, 441 | "metadata": {}, 442 | "outputs": [], 443 | "source": [ 444 | "account1.withdraw(399)" 445 | ] 446 | }, 447 | { 448 | "cell_type": "code", 449 | "execution_count": null, 450 | "metadata": {}, 451 | "outputs": [], 452 | "source": [ 453 | "import math\n", 454 | "\n", 455 | "\n", 456 | "class Cone:\n", 457 | " def __init__(self,r=1,h=1):\n", 458 | " self.r = r\n", 459 | " self.h = h\n", 460 | " self.volume =0\n", 461 | " self.surface_area = 0\n", 462 | " \n", 463 | " def volume_fun(self):\n", 464 | " self.volume = math.pi * self.r * self.r * (self.h/3)\n", 465 | " return self.volume\n", 466 | " \n", 467 | " def surface_area_fun(self):\n", 468 | " base = math.pi * self.r * self.r\n", 469 | " side = math.pi * self.r * math.sqrt(self.r**2 + self.h**2)\n", 470 | " self.surface_area = base + side\n", 471 | " return self.surface_area\n", 472 | " " 473 | ] 474 | }, 475 | { 476 | "cell_type": "code", 477 | "execution_count": null, 478 | "metadata": {}, 479 | "outputs": [], 480 | "source": [ 481 | "cone1 = Cone(5,7)" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": null, 487 | "metadata": {}, 488 | "outputs": [], 489 | "source": [ 490 | "cone1.volume_fun()" 491 | ] 492 | }, 493 | { 494 | "cell_type": "code", 495 | "execution_count": null, 496 | "metadata": {}, 497 | "outputs": [], 498 | "source": [ 499 | "cone1.surface_area_fun()" 500 | ] 501 | }, 502 | { 503 | "cell_type": "code", 504 | "execution_count": 1, 505 | "metadata": {}, 506 | "outputs": [ 507 | { 508 | "data": { 509 | "text/plain": [ 510 | "map" 511 | ] 512 | }, 513 | "execution_count": 1, 514 | "metadata": {}, 515 | "output_type": "execute_result" 516 | } 517 | ], 518 | "source": [ 519 | "map" 520 | ] 521 | }, 522 | { 523 | "cell_type": "code", 524 | "execution_count": null, 525 | "metadata": {}, 526 | "outputs": [], 527 | "source": [] 528 | } 529 | ], 530 | "metadata": { 531 | "kernelspec": { 532 | "display_name": "Python 3", 533 | "language": "python", 534 | "name": "python3" 535 | }, 536 | "language_info": { 537 | "codemirror_mode": { 538 | "name": "ipython", 539 | "version": 3 540 | }, 541 | "file_extension": ".py", 542 | "mimetype": "text/x-python", 543 | "name": "python", 544 | "nbconvert_exporter": "python", 545 | "pygments_lexer": "ipython3", 546 | "version": "3.7.4" 547 | } 548 | }, 549 | "nbformat": 4, 550 | "nbformat_minor": 2 551 | } 552 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LetsUpgrade-FCS-Python -------------------------------------------------------------------------------- /SILVER PROJECT - Parth Patel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "7 8 9\n", 13 | "4 5 6\n", 14 | "1 2 3\n", 15 | "\n", 16 | "Player 1 choose where to place a cross\n", 17 | "1\n", 18 | "\n", 19 | "7 8 9\n", 20 | "4 5 6\n", 21 | "X 2 3\n", 22 | "\n", 23 | "Player 2 choose where to place a nought\n", 24 | "4\n", 25 | "\n", 26 | "7 8 9\n", 27 | "O 5 6\n", 28 | "X 2 3\n", 29 | "\n", 30 | "Player 1 choose where to place a cross\n", 31 | "5\n", 32 | "\n", 33 | "7 8 9\n", 34 | "O X 6\n", 35 | "X 2 3\n", 36 | "\n", 37 | "Player 2 choose where to place a nought\n", 38 | "7\n", 39 | "\n", 40 | "O 8 9\n", 41 | "O X 6\n", 42 | "X 2 3\n", 43 | "\n", 44 | "Player 1 choose where to place a cross\n", 45 | "9\n", 46 | "\n", 47 | "O 8 X\n", 48 | "O X 6\n", 49 | "X 2 3\n", 50 | "\n", 51 | "Player 1 Wins!\n", 52 | "\n", 53 | "Congratulations!\n", 54 | "\n", 55 | "Play again (y/n)\n", 56 | "y\n", 57 | "\n", 58 | "7 8 9\n", 59 | "4 5 6\n", 60 | "1 2 3\n", 61 | "\n", 62 | "Player 1 choose where to place a cross\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "def tic_tac_toe():\n", 68 | " board = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", 69 | " end = False\n", 70 | " win_commbinations = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6))\n", 71 | "#print board\n", 72 | " def draw():\n", 73 | " print(board[6], board[7], board[8])\n", 74 | " print(board[3], board[4], board[5])\n", 75 | " print(board[0], board[1], board[2])\n", 76 | " print()\n", 77 | "\n", 78 | " def p1():\n", 79 | " n = choose_number()\n", 80 | " if board[n] == \"X\" or board[n] == \"O\":\n", 81 | " print(\"\\nYou can't go there. Try again\")\n", 82 | " p1()\n", 83 | " else:\n", 84 | " board[n] = \"X\"\n", 85 | "\n", 86 | " def p2():\n", 87 | " n = choose_number()\n", 88 | " if board[n] == \"X\" or board[n] == \"O\":\n", 89 | " print(\"\\nYou can't go there. Try again\")\n", 90 | " p2()\n", 91 | " else:\n", 92 | " board[n] = \"O\"\n", 93 | "#make loop\n", 94 | " def choose_number():\n", 95 | " while True:\n", 96 | " while True:\n", 97 | " a = input()\n", 98 | " try:\n", 99 | " a = int(a)\n", 100 | " a -= 1\n", 101 | " if a in range(0, 9):\n", 102 | " return a\n", 103 | " else:\n", 104 | " print(\"\\nThat's not on the board. Try again\")\n", 105 | " continue\n", 106 | " except ValueError:\n", 107 | " print(\"\\nThat's not a number. Try again\")\n", 108 | " continue\n", 109 | "\n", 110 | " def check_board():\n", 111 | " count = 0\n", 112 | " for a in win_commbinations:\n", 113 | " if board[a[0]] == board[a[1]] == board[a[2]] == \"X\":\n", 114 | " print(\"Player 1 Wins!\\n\")\n", 115 | " print(\"Congratulations!\\n\")\n", 116 | " return True\n", 117 | "\n", 118 | " if board[a[0]] == board[a[1]] == board[a[2]] == \"O\":\n", 119 | " print(\"Player 2 Wins!\\n\")\n", 120 | " print(\"Congratulations!\\n\")\n", 121 | " return True\n", 122 | " for a in range(9):\n", 123 | " if board[a] == \"X\" or board[a] == \"O\":\n", 124 | " count += 1\n", 125 | " if count == 9:\n", 126 | " print(\"The game ends in a Tie\\n\")\n", 127 | " return True\n", 128 | "\n", 129 | " while not end:\n", 130 | " draw()\n", 131 | " end = check_board()\n", 132 | " if end == True:\n", 133 | " break\n", 134 | " print(\"Player 1 choose where to place a cross\")\n", 135 | " p1()\n", 136 | " print()\n", 137 | " draw()\n", 138 | " end = check_board()\n", 139 | " if end == True:\n", 140 | " break\n", 141 | " print(\"Player 2 choose where to place a nought\")\n", 142 | " p2()\n", 143 | " print()\n", 144 | "\n", 145 | " if input(\"Play again (y/n)\\n\") == \"y\":\n", 146 | " print()\n", 147 | " tic_tac_toe()\n", 148 | "\n", 149 | "tic_tac_toe()" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [] 158 | } 159 | ], 160 | "metadata": { 161 | "kernelspec": { 162 | "display_name": "Python 3", 163 | "language": "python", 164 | "name": "python3" 165 | }, 166 | "language_info": { 167 | "codemirror_mode": { 168 | "name": "ipython", 169 | "version": 3 170 | }, 171 | "file_extension": ".py", 172 | "mimetype": "text/x-python", 173 | "name": "python", 174 | "nbconvert_exporter": "python", 175 | "pygments_lexer": "ipython3", 176 | "version": "3.6.10" 177 | } 178 | }, 179 | "nbformat": 4, 180 | "nbformat_minor": 4 181 | } 182 | -------------------------------------------------------------------------------- /TIC TAC TOE .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "from IPython.display import clear_output\n", 10 | "\n", 11 | "def display_board(board):\n", 12 | " clear_output()\n", 13 | " print(' '+board[7]+' | '+board[8]+' | '+board[9]+' ')\n", 14 | " print('---------')\n", 15 | " print(' '+board[4]+' | '+board[5]+' | '+board[6]+' ')\n", 16 | " print('---------')\n", 17 | " print(' '+board[1]+' | '+board[2]+' | '+board[3]+' ')\n", 18 | " " 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "board = ['#','X','O','X','O','X','O','X','O','X','O']" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 3, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | " X | O | X \n", 47 | "---------\n", 48 | " O | X | O \n", 49 | "---------\n", 50 | " X | O | X \n" 51 | ] 52 | } 53 | ], 54 | "source": [ 55 | "display_board(board)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 4, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "def player_input():\n", 65 | " marker = ''\n", 66 | " \n", 67 | " while not (marker == 'X' or marker == \"O\"):\n", 68 | " marker = input(\"Enter a Marker X/O for player one : \").upper()\n", 69 | " \n", 70 | " if marker == 'X':\n", 71 | " return ('X','O')\n", 72 | " else:\n", 73 | " return ('O','X')\n" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 5, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "Enter a Marker X/O for player one : h\n", 86 | "Enter a Marker X/O for player one : x\n" 87 | ] 88 | }, 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "('X', 'O')" 93 | ] 94 | }, 95 | "execution_count": 5, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "player_input()" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 6, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "def place_marker(board,marker,position):\n", 111 | " board[position] = marker" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 11, 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [ 120 | "place_marker(board,\"X\",5)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 12, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | " X | O | X \n", 133 | "---------\n", 134 | " O | X | O \n", 135 | "---------\n", 136 | " X | O | X \n" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "display_board(board)" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 14, 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "def win_check(board,marker):\n", 151 | " \n", 152 | " if( (board[7]==marker and board[8]==marker and board[9]==marker) or\n", 153 | " (board[4]==marker and board[5]==marker and board[6]==marker) or\n", 154 | " (board[1]==marker and board[2]==marker and board[3]==marker) or\n", 155 | " (board[7]==marker and board[4]==marker and board[1]==marker) or\n", 156 | " (board[8]==marker and board[5]==marker and board[2]==marker) or\n", 157 | " (board[9]==marker and board[6]==marker and board[3]==marker) or\n", 158 | " (board[7]==marker and board[5]==marker and board[3]==marker) or\n", 159 | " (board[9]==marker and board[5]==marker and board[1]==marker)):\n", 160 | " return True\n", 161 | " else:\n", 162 | " return False" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 15, 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "True" 174 | ] 175 | }, 176 | "execution_count": 15, 177 | "metadata": {}, 178 | "output_type": "execute_result" 179 | } 180 | ], 181 | "source": [ 182 | "win_check(board,'X')" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 16, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "data": { 192 | "text/plain": [ 193 | "False" 194 | ] 195 | }, 196 | "execution_count": 16, 197 | "metadata": {}, 198 | "output_type": "execute_result" 199 | } 200 | ], 201 | "source": [ 202 | "win_check(board,'O')" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 17, 208 | "metadata": {}, 209 | "outputs": [], 210 | "source": [ 211 | "import random \n", 212 | "\n", 213 | "def choose_first():\n", 214 | " num = random.randint(0,1)\n", 215 | " \n", 216 | " if num == 1:\n", 217 | " return 'Player 1'\n", 218 | " else:\n", 219 | " return 'Player 2'" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": 24, 225 | "metadata": {}, 226 | "outputs": [ 227 | { 228 | "data": { 229 | "text/plain": [ 230 | "'Player 1'" 231 | ] 232 | }, 233 | "execution_count": 24, 234 | "metadata": {}, 235 | "output_type": "execute_result" 236 | } 237 | ], 238 | "source": [ 239 | "choose_first()" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 25, 245 | "metadata": {}, 246 | "outputs": [], 247 | "source": [ 248 | "board = ['#','X',' ',' ','O','X',' ','X',' ','X','O']" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 26, 254 | "metadata": {}, 255 | "outputs": [], 256 | "source": [ 257 | "def space_check(board,position):\n", 258 | " return board[position] == ' '" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 27, 264 | "metadata": {}, 265 | "outputs": [ 266 | { 267 | "data": { 268 | "text/plain": [ 269 | "True" 270 | ] 271 | }, 272 | "execution_count": 27, 273 | "metadata": {}, 274 | "output_type": "execute_result" 275 | } 276 | ], 277 | "source": [ 278 | "space_check(board,6)" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 28, 284 | "metadata": {}, 285 | "outputs": [], 286 | "source": [ 287 | "def full_board_check(board):\n", 288 | " isFull = True\n", 289 | " for i in board:\n", 290 | " if i == ' ':\n", 291 | " isFull = False\n", 292 | " return isFull\n", 293 | " " 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": 29, 299 | "metadata": {}, 300 | "outputs": [ 301 | { 302 | "data": { 303 | "text/plain": [ 304 | "False" 305 | ] 306 | }, 307 | "execution_count": 29, 308 | "metadata": {}, 309 | "output_type": "execute_result" 310 | } 311 | ], 312 | "source": [ 313 | "full_board_check(board)" 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": 30, 319 | "metadata": {}, 320 | "outputs": [], 321 | "source": [ 322 | "def full_board_check(board):\n", 323 | " for i in range(1,10):\n", 324 | " if space_check(board,i):\n", 325 | " return False\n", 326 | " return True" 327 | ] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "execution_count": 31, 332 | "metadata": {}, 333 | "outputs": [ 334 | { 335 | "data": { 336 | "text/plain": [ 337 | "False" 338 | ] 339 | }, 340 | "execution_count": 31, 341 | "metadata": {}, 342 | "output_type": "execute_result" 343 | } 344 | ], 345 | "source": [ 346 | "full_board_check(board)" 347 | ] 348 | }, 349 | { 350 | "cell_type": "code", 351 | "execution_count": 32, 352 | "metadata": {}, 353 | "outputs": [], 354 | "source": [ 355 | "def players_choice(board):\n", 356 | " position = 0\n", 357 | " \n", 358 | " while not position in [1,2,3,4,5,6,7,8,9] or not space_check(board,position) : \n", 359 | " position = int(input(\"Enter your next position : \"))\n", 360 | " \n", 361 | " return position" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": 33, 367 | "metadata": {}, 368 | "outputs": [ 369 | { 370 | "name": "stdout", 371 | "output_type": "stream", 372 | "text": [ 373 | "Enter your next position : 100\n", 374 | "Enter your next position : 3\n", 375 | "Enter your next position : 6\n" 376 | ] 377 | }, 378 | { 379 | "data": { 380 | "text/plain": [ 381 | "6" 382 | ] 383 | }, 384 | "execution_count": 33, 385 | "metadata": {}, 386 | "output_type": "execute_result" 387 | } 388 | ], 389 | "source": [ 390 | "players_choice(board)" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": 34, 396 | "metadata": {}, 397 | "outputs": [], 398 | "source": [ 399 | "def replay():\n", 400 | " return input(\"Do you want to play again (Y/N) : \").lower().startswith('y')" 401 | ] 402 | }, 403 | { 404 | "cell_type": "code", 405 | "execution_count": 37, 406 | "metadata": {}, 407 | "outputs": [ 408 | { 409 | "name": "stdout", 410 | "output_type": "stream", 411 | "text": [ 412 | "Do you want to play again (Y/N) : h\n" 413 | ] 414 | }, 415 | { 416 | "data": { 417 | "text/plain": [ 418 | "False" 419 | ] 420 | }, 421 | "execution_count": 37, 422 | "metadata": {}, 423 | "output_type": "execute_result" 424 | } 425 | ], 426 | "source": [ 427 | "replay()" 428 | ] 429 | }, 430 | { 431 | "cell_type": "code", 432 | "execution_count": 38, 433 | "metadata": {}, 434 | "outputs": [ 435 | { 436 | "name": "stdout", 437 | "output_type": "stream", 438 | "text": [ 439 | " O | O | \n", 440 | "---------\n", 441 | " X | O | \n", 442 | "---------\n", 443 | " X | O | X \n", 444 | "Player 2 Won the game!! congratzz\n", 445 | "Do you want to play again (Y/N) : n\n" 446 | ] 447 | } 448 | ], 449 | "source": [ 450 | "# Here Comes the final Assembly of the game \n", 451 | "\n", 452 | "\n", 453 | "while True:\n", 454 | " \n", 455 | " board = [' ']* 10\n", 456 | " \n", 457 | " \n", 458 | " player1_marker, player2_marker = player_input()\n", 459 | " turn = choose_first()\n", 460 | " \n", 461 | " print(turn + \" Will play First\")\n", 462 | " \n", 463 | " play_game = input(\"Are you ready to play the game Y/N\").lower().startswith('y')\n", 464 | " \n", 465 | " if play_game:\n", 466 | " game_on = True\n", 467 | " else:\n", 468 | " game_on = False\n", 469 | " \n", 470 | " while game_on:\n", 471 | " if turn == 'Player 1':\n", 472 | " # Game logic starts here for player 1 \n", 473 | " \n", 474 | " display_board(board)\n", 475 | " position = players_choice(board)\n", 476 | " place_marker(board,player1_marker,position)\n", 477 | " \n", 478 | " if win_check(board,player1_marker):\n", 479 | " display_board(board)\n", 480 | " print(\"Player 1 Won the game!! congratzz\")\n", 481 | " game_on = False\n", 482 | " else:\n", 483 | " if full_board_check(board):\n", 484 | " display_board(board)\n", 485 | " print('The Game is Draw, Better luck next time !!')\n", 486 | " break\n", 487 | " else:\n", 488 | " turn = \"Player 2\"\n", 489 | " else:\n", 490 | " # Player 2 Logic \n", 491 | " \n", 492 | " display_board(board)\n", 493 | " position = players_choice(board)\n", 494 | " place_marker(board,player2_marker,position)\n", 495 | " \n", 496 | " if win_check(board,player2_marker):\n", 497 | " display_board(board)\n", 498 | " print(\"Player 2 Won the game!! congratzz\")\n", 499 | " game_on = False\n", 500 | " else:\n", 501 | " if full_board_check(board):\n", 502 | " display_board(board)\n", 503 | " print('The Game is Draw, Better luck next time !!')\n", 504 | " break\n", 505 | " else:\n", 506 | " turn = \"Player 1\"\n", 507 | " \n", 508 | " if not replay():\n", 509 | " break " 510 | ] 511 | }, 512 | { 513 | "cell_type": "code", 514 | "execution_count": null, 515 | "metadata": {}, 516 | "outputs": [], 517 | "source": [] 518 | } 519 | ], 520 | "metadata": { 521 | "kernelspec": { 522 | "display_name": "Python 3", 523 | "language": "python", 524 | "name": "python3" 525 | }, 526 | "language_info": { 527 | "codemirror_mode": { 528 | "name": "ipython", 529 | "version": 3 530 | }, 531 | "file_extension": ".py", 532 | "mimetype": "text/x-python", 533 | "name": "python", 534 | "nbconvert_exporter": "python", 535 | "pygments_lexer": "ipython3", 536 | "version": "3.7.4" 537 | } 538 | }, 539 | "nbformat": 4, 540 | "nbformat_minor": 2 541 | } 542 | -------------------------------------------------------------------------------- /__pycache__/cap.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sai-sondarkar/LetsUpgrade-FCS-Python/3901a48f4404b74d7f6915e964ccffe92e5cda16/__pycache__/cap.cpython-37.pyc -------------------------------------------------------------------------------- /assignment3.txt: -------------------------------------------------------------------------------- 1 | I love and live for FCS -------------------------------------------------------------------------------- /cap.py: -------------------------------------------------------------------------------- 1 | def cap_text(text): 2 | return text.title() 3 | -------------------------------------------------------------------------------- /day 2 - piyush takale.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 9, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#file operations\n", 10 | "\n", 11 | "file=open('sample1.txt','w')\n", 12 | "file.write(\"sample text at line 1\")\n", 13 | "file.write(\"line2\")\n", 14 | "file.close()" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 10, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "sample text at line 1line2\n" 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "#read file\n", 32 | "\n", 33 | "file=open('sample1.txt','r')\n", 34 | "data=file.read()\n", 35 | "print(data)\n", 36 | "file.close()" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 13, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "#append file\n", 46 | "\n", 47 | "file=open('sample1.txt','a')\n", 48 | "file.write(\"\\nthis is line 3\")\n", 49 | "file.close()" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 17, 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "a is large\n", 62 | "True\n", 63 | "False\n", 64 | "False\n", 65 | "True\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "#comparizon operators\n", 71 | "\n", 72 | "a=12\n", 73 | "b=11\n", 74 | "\n", 75 | "if(a=b)\n", 81 | "print(a<=b)\n", 82 | "print(a==b)\n", 83 | "print(a!=b)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 18, 89 | "metadata": {}, 90 | "outputs": [ 91 | { 92 | "name": "stdout", 93 | "output_type": "stream", 94 | "text": [ 95 | "False\n", 96 | "True\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "#AND and check both conditions\n", 102 | "a=5\n", 103 | "b=6\n", 104 | "\n", 105 | "print(a>b and a<10)\n", 106 | "print(ab or a<10)\n", 127 | "print(ab or a<3)" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 23, 134 | "metadata": {}, 135 | "outputs": [ 136 | { 137 | "name": "stdout", 138 | "output_type": "stream", 139 | "text": [ 140 | "True\n", 141 | "False\n", 142 | "False\n", 143 | "True\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "#not\n", 149 | "\n", 150 | "data = ab or a<3\n", 154 | "print(data)\n", 155 | "print(not data)" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 37, 161 | "metadata": {}, 162 | "outputs": [ 163 | { 164 | "name": "stdout", 165 | "output_type": "stream", 166 | "text": [ 167 | "we cant take class\n" 168 | ] 169 | } 170 | ], 171 | "source": [ 172 | "sir={\"teach\":\"false\",\"im_free\":\"false\"}\n", 173 | "\n", 174 | "if(sir[\"teach\"]==\"true\" and sir[\"im_free\"]==\"false\"):\n", 175 | " print(\"sir is teching but student are not free\")\n", 176 | "elif(sir[\"teach\"]==\"true\" and sir[\"im_free\"]==\"true\"):\n", 177 | " print(\"we can take class\")\n", 178 | "elif(sir[\"teach\"]==\"false\" and sir[\"im_free\"]==\"false\"):\n", 179 | " print(\"we cant take class\")" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 38, 185 | "metadata": {}, 186 | "outputs": [ 187 | { 188 | "name": "stdout", 189 | "output_type": "stream", 190 | "text": [ 191 | "1\n", 192 | "2\n", 193 | "3\n", 194 | "4\n", 195 | "5\n", 196 | "6\n", 197 | "7\n", 198 | "8\n", 199 | "9\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "lis=[1,2,3,4,5,6,7,8,9]\n", 205 | "\n", 206 | "for els in lis:\n", 207 | " print(els)" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "metadata": {}, 214 | "outputs": [], 215 | "source": [] 216 | } 217 | ], 218 | "metadata": { 219 | "kernelspec": { 220 | "display_name": "Python 3", 221 | "language": "python", 222 | "name": "python3" 223 | }, 224 | "language_info": { 225 | "codemirror_mode": { 226 | "name": "ipython", 227 | "version": 3 228 | }, 229 | "file_extension": ".py", 230 | "mimetype": "text/x-python", 231 | "name": "python", 232 | "nbconvert_exporter": "python", 233 | "pygments_lexer": "ipython3", 234 | "version": "3.7.6" 235 | } 236 | }, 237 | "nbformat": 4, 238 | "nbformat_minor": 4 239 | } 240 | -------------------------------------------------------------------------------- /fcs.txt: -------------------------------------------------------------------------------- 1 | Hey we are loving the class -------------------------------------------------------------------------------- /fcs1.txt: -------------------------------------------------------------------------------- 1 | Hey we are coding along Python Files 2 | We are completing today File handling -------------------------------------------------------------------------------- /letsupgrade.txt: -------------------------------------------------------------------------------- 1 | This is the write command 2 | It allows us to write in a particular file -------------------------------------------------------------------------------- /simpletest.py: -------------------------------------------------------------------------------- 1 | a=1 2 | b=2 3 | print(a) 4 | print(b) 5 | -------------------------------------------------------------------------------- /test_cap.py: -------------------------------------------------------------------------------- 1 | 2 | import unittest 3 | import cap 4 | 5 | class TestCap(unittest.TestCase): 6 | 7 | def test_one_word(self): 8 | text = "python" 9 | result = cap.cap_text(text) 10 | self.assertEqual(result,'Python') 11 | 12 | def test_multiple_words(self): 13 | text = "itm fcs" 14 | result = cap.cap_text(text) 15 | self.assertEqual(result,'Itm Fcs') 16 | 17 | if __name__ == '__main__': 18 | unittest.main() 19 | -------------------------------------------------------------------------------- /testfile: -------------------------------------------------------------------------------- 1 | This is awsm --------------------------------------------------------------------------------