Submind YouTube summaries
Thumbnail for Learn Python by Building 2 Projects

Learn Python by Building 2 Projects

Watch on YouTube

Video summary

This Python course is designed to build practical skills through a structured approach that begins with warm-up exercises before moving on to three main projects. Learners start by solving practice questions from PDFs and then utilize blank Jupyter notebooks to complete code for Tic-Tac-Toe and Number Guessing games, following provided comments. To get started, users must install Anaconda via its Windows installer, launch the Navigator, and access Jupyter Notebook through a web interface where code is written in cells and executed using the "Run" button or keyboard shortcuts like Ctrl+Enter. The tutorial also covers essential notebook management tasks such as saving work, inserting new cells, cutting and pasting code, reordering cells, and interrupting infinite loops using the kernel interrupt button. The Number Guessing Game tutorial introduces fundamental concepts like generating random numbers with the `random` module's `randrange` method and creating delays using `time.sleep`. It teaches how to capture user input as strings, convert them to integers, and apply logic using `while` loops, `if/elif/else` statements, and `break` commands to exit loops. Initially allowing unlimited guesses, the game is later modified to limit attempts to five by using a counter variable and formatted messages to track remaining tries. The Tic-Tac-Toe section explains the mechanics of two players taking turns on a grid, while introducing Python dictionaries as ordered collections of unique key-value pairs used to store game data efficiently. The course delves deeper into dictionary usage for the Tic-Tac-Toe game, showing how to store grid positions as string keys with values representing X, O, or empty spaces. It demonstrates iterating through dictionaries to access keys, appending them to lists, and combining multiple variables in a single print statement to create the visual 3x3 grid using whitespace and dashes. Crucial game logic is implemented by checking if positions are empty before updating them, alternating turns between players using conditional statements, and defining win conditions where three specific keys hold identical non-empty values. The guide concludes this phase by explaining how to define and call functions to structure the complete game code, ensuring a clean and organized program. In conclusion, the speaker encourages viewers to recall all the functionalities discussed throughout the course and emphasizes the importance of consistent practice to master these skills. By working through the provided projects and exercises, learners gain hands-on experience with core Python concepts such as loops, conditionals, modules, and data structures like dictionaries. The video ends with a farewell wish for a pleasant learning experience, inviting students to apply what they have learned to build their own projects and continue their journey in Python programming.
Read the full video transcript
welcome friends now let's discuss that what is the structure of our study material and practice set so basically if I talk about practice site practice set contains of some PDFs in this PDF you will get 100 plus of questions which are required to build the basic understanding for our basic logic which are required for this basic projects okay so you have to sort this out Hello friends if I talk about basic projects folder this folder consists of three folders okay whenever you are going to start learning that projects so the structure of this course is that in that way that you have to first learn the warm-up exercise okay so when you are going to learn that warm-up exercise and after completing that lecture you just need to open this warm-up exercise folder okay and try to solve this blank jupy notebook okay in this blank Jupiter notebook you will get these two tic-tac-toe game and number guessing game so after warm-up exercise you need to do what you need to solve this exercises okay which are blank you have given I have given all the comments which are required okay and you just need to read the comment and what you have to do code according to that comment okay let this Jupiter notebook open and I will explain you how so I have given this for example as a right here import random module what you are going to use okay so according to that lecture you have to work on it okay so this will help you to give you best practice okay and after these warm-up exercises what you have to do after this warm-up exercises you have to go to you have to come here and create this blank Jupiter notebook okay so in blank Jupiter notebook I have given number guessing game and tic-tac-toe game okay so in this stupid notebook I have also mentioned what I also I mentioned here comments which are the task which we have to complete to create this game okay and this exercise will help you to be better and improve yourself okay so I hope you are going to practice more and learn more okay so welcome back friends so in this lecture we are going to learn about how you can install jupyter notebook so the best thing is that to install Jupiter notebook just you need to install Anaconda game so just search Anaconda download okay and when you click here just you need to click here on downloads okay when you download you just need to select which operating system you are using so as I am using basically Windows operating system so I click here when you click here there is an exe file start downloading okay I'm going to cancel it because I have already have this Anaconda exe file so for yours you need to download it when you download it this exe file you need to run this exe file okay so when you run this exe file you need to accept some terms and conditions and you will install this Anaconda in your computer or laptop after installing anaconda in your laptop or computer you just need to search Anaconda Navigator and you have to click on Anaconda navigate when you click on the Anaconda Navigator it will take near about one to two minute to open it okay so you have to wait for some minutes this kind of screens you can see when this Anaconda is opening in your laptop so it is taking some time foreign you can skip some minutes okay or some seconds to watch so as you can see here this is the Anaconda Navigator okay so there are a bunch of softwares and other things available here so we just need to open jupyter notebook because uh for this lecture or with this setting with this course we are going to use jupyter notebook as our uh editor okay so you just need to click here on launch and that jupyter notebook will launch okay so this is how you need to use it in next video we are going to learn about how to use jupyter notebook so I hope you understand about that how to install Jupiter in your computer so just let me give a quick recap that you just need to install Anaconda okay when you install Anaconda you just need to run Anaconda Navigator in your laptop okay when you open Anaconda Navigator this type of screen is going to show you then you just need to go and click on Jupiter okay notebook when you click on launch you will see a web-based pro okay web based interface interface open in your screen in your default browser so welcome back friends so in this lecture I am going to tell you about how to use jupyter notebook okay so after opening jupyter notebook using Anaconda Navigator you will see this kind of web interface okay where you will see the list of folders and files right so now in this list of folders you need to search or select your folder where you want to save your work so for this course I am going to select udemy python folder where I am going to save all my work done during this course okay I will share this folder with you okay in next video you can see how to download these folders so before uh we've moved further let me explain you how to use in Jupiter notebook okay so whenever you want to create a new jupyter notebook okay you just need to click here on new button when you click on the new button you will see bunch of options just okay so you just need to click here on python 3. when you click on Python 3 this uh new web page open okay which is Jupiter notebook basically now here you can see this is called cell okay so in this cell you need to write the code python code which you want to execute okay so for example uh if I want to print hello world so let me write code for printing hello word so print hello world no whenever you have done return your code there are two ways to execute this code okay uh first way is either you can click here on run cell okay when you click on this button the cell will execute and you will see the output here okay so this functionality makes Jupiter easy to use okay because user doesn't need to switch multiple screens to run the python code and see what's the output of its python code okay so this functionality make user Make This Jupiter very popular okay and uh and you can generally see that okay so you need to just write the code here and you need to execute the code and you will see the output here okay apart from this uh there is an another way to execute this cell is Control Plus enter so when you enter uh Control Plus enter you will see this cell will execute okay so there are two ways either you can use run button or you can use Control Plus enter to run this cell okay now let's discuss more about this button given here okay which are very useful during execution or when we use jupyter notebook this button will help you a lot so let's start with this button okay so this button is used to save okay so uh basically this button is used to store uh you can say save your work so whenever you write your code and you want to just finish your work and save you can use this button okay if we talk about this button this button gives us function uh extra basically this button can insert cell okay so you can insert this cell or add new cell in your jupyter notebook by using multiple cell uh we can divide our code into multiple parts and which help us to understand our code working okay so this help us to understand our code logical we can divide our code into multiple steps and we can find that in first step we find uh this output in second step we find this output okay so we can compare it in next three uh buttons you can see here these are cut copy and paste okay so you can use uh using this cell you can cut the cell using this button you can copy the cell using this button you can pass to the cell okay now these two arrows are used to move the cell okay so if you want to move yourself up you can use this if you want to move your cell down you can use this button okay now we have already discussed this cell this cell is used to run the or execute this cell okay so if you write some code and if you want to execute that code you can use this button now let me explain you this button okay this button is known as interrupt the kernel okay basically what happens uh whenever we use or write python code okay for example I was using while loop while loop okay so let me give some condition here so if I initialize I equals to 0 and create a condition that this while loop only execute when I is less than 10 okay and you just need to print I value of I and we are increasing the value of I by 1 after each iteration okay so let me write I equals to I Plus 12. so you can see when we execute this cell we find output from 0 to 9 okay because this while loop is going to execute for 10 times and for the I value of 0 to 9 now if we uh by mistake you know we made a logical mistake like we never assign or increment the value of I so in this condition what is going to happen in this condition our Loop is going to execute for infinity times because this condition is always going to return true okay so as you can see you will see the multiple times your our interpreter is interpreting our our code will executing again and again okay so in this condition we use this okay in this condition whenever we make any mistake which basically it's a logical mistake which put our program into Infinity loops so we use this button so when we when you press this button what happened the interruption basically Interruption occur Okay so the execution of this cell is stopped so this is uh mostly used when what happened when you go towards infinity loop okay so I hope you understand about these functionalities of jupyter notebook okay so basically this is the basic introduction of Jupiter notebook I hope you learned about it and if you encounter any error error or say any difficulties you can Google it okay there are a bunch of questions available and bunch of very vast community of Jupiter notebook users they will answer you so so see you in next lecture till then take care Hello friends so in this lecture basically I am going to tell you how to use or how to easily open that Jupiter notebook so just you need to press the Windows key search CMD and open the command prompt okay and in command from just right Peter space node group then 2 Dash and then again write notebook and after that write Dash then write dir means directory equals to C okay Capital C and column and enter this is how you can easily the this is the very easiest way to open jupyter notebook okay this is how you can open the jupyter notebook very basic and easiest way okay if you understand I will give this uh this command in an article where you can find it okay thank you welcome back friends so in this lecture we are going to discuss about what is number guessing game okay so before we create this number guessing game let's play this game to understand about its functionality so basically this game is very simple so what happened in this game is computer generate a number between 1 200 and user need to find or guess the number generated by the computer easy so let's play and enjoy this game so let me run this code so I have two options as we have already discussed earlier that I I can click on the Run button or you I can use Control Plus enter so when you hit Control Plus enter this will execute okay now so first what we get we get a number message welcome to the number guessing game and the number range between 1 2 100 now so at this position at this particular event what happened is a computer has already generated a number okay so we what we have to do is uh we have to find that or guess that number so let's guess uh let's guess 40. so we got a message that this number is too low then guess again so let's guess 50. again we got a message that this number is too low so let's get 70. again we've got a message that this number is too low means neither be a let's write 90. it's too high okay so we can find out that uh our number which we have to guess is greater than 70 and less than 90 because we got a message too high so now let's guess at T 80 is to go it means we can say that the number which we have to guess is greater than at T and lower than 90. so it basically let's try 85. okay 85 is too low also so near try between 87 it's too low again so let's try 88 oops yes so we find out the number so this is how this game works okay welcome back friends so in this lecture we are going to perform some warm-up exercise for number guessing game basically these are some things which we are going to use to create number guessing game so before we are going to create that game Let's uh understand or recap this Logics and how we can use if statement as a statement what is if I leave a statement how to implement while loop in Python and how to get input from the user and how to import modules and how we can use modules functions and method in our program so let's try or let's start this thing okay so basically what we are going uh if I talk about random module so basically what why we are using this random model because we want to generate a random number okay so basically to generate a random number we are using random range okay random Fringe method which is basically we are using this method and what this method can do basically this method takes two argument okay so first argument is starting range and the second one is stop where to stop okay so basically what happens whenever you run this code okay so what we are doing is basically it's just V in first line we are importing random module and from random model what we are going to use we are using random range method okay so basically whatever the value this method will return we are going to assigning it we are going to assign it into this variable known as n okay and we are going to print it so let uh have a look that how this is going to execute okay so when we execute this we get 29 okay so let's execute again again and see we will get always a random number okay as you can see so basically we are using this random range method to generate a random number in between 1 200 okay now comes let's come to time module okay so basically why we are using time modding because we want a two second delay okay and in our code okay so basically for two second delay what we are using we are using slip function okay so basically in slip function what we need to do is we need to mention or we need to pass argument for example if I write it here 2 so basically what is going to happen let's see this is going to give a two second delay in our program execution as you can see here see again you just printed start and after printing start photos after two second he is going to print stop okay so how to use this we just need to import the time module by writing import keyword and writing the model name time and when we import the time model then we are using what time dot sleep this sleep function will help us to put a delay okay in our execution if I put 5 here then that see what happens we got a print we got a print start and after five seconds we this is going to print stop okay I hope you understand how this lay function works okay now let's come to how to take input from the user okay so basically whenever you want to take any input from the user we we use input method okay now how this method works so basically we need to write input and a message which user want we want to display to the user okay so let's let me run this code okay and so you can see this type of thing okay so here this is our message which one we want to see during the execution of the code and so basically what is going to happen here whenever user enter a number it's going to assign it to this number one variable okay number one variable okay so if I write 20 then what's going to happen it's going to assign to the num but you have to see one thing okay whenever you use input method it always gives value in string format okay string data type okay so as you can see here v as we as I give number 20 okay here it will print 20 but whenever see the type of number one number one we find that that number belongs to class Str it means that value which this number one is holding is what kind of its kind of basically its belong to string okay so now what we need to do this how to uh basically for this problem we use type casting okay so basically what is Type casting we convert the type of the input so basically the user gives us a value for example let's see again if I enter 20 what will happen C this input method will return as a value in form of string so basically when user enter 20 so what this value gives this input method gives value 20 and then we convert this 20 into a integer type okay and then assign it to the num1 okay so whenever I hope you understand how this works okay so let me undo this so basically what is going to happen here after execution this line the number one or we can say the num1 variable holds a integer value okay so let if we print that integer value or the number we get our value and when we find the type of this num1 we will find that common belongs to integer class okay now next is our while loop so I hope that you know how to use while loop basically so whenever you want to use while loop you just need to mention while keyword and then you have to write a condition here which is based on any code logic which you want to implement so basically I have using here account variable okay so this count variable what he is doing we are assigning it by default by one okay so what is going to do basically what happens uh when interpreter execute this line it basically assign a variable count and assign a number one okay so basically the value of count is one now what is going to happen now when this while loop execute it will check this condition if this condition returns true then this body is going to execute okay so for it each iteration what will happen for each iteration this condition is going to be checked okay if this condition returns true then this going this body is going to execute otherwise if this condition returns false then what will happen this body or this while loop will terminate okay so let's see how this work as you can see what output we got basically we are if we see we can see this this while loop is going to execute for four times okay why it's going to execute for four times because the value of count s from 1 and goes to 4. and when we encounter this condition for example in after fourth iteration the value of count become 5 okay when the value peak of count become 5 you can see this condition is going to return false okay and when this condition returns false this while loop is going to terminate and going to print side while okay this message I hope you understand how this file is working now and what this rule of count is here to basically count gives us a H basically this what we can say this condition is depending on count value okay so for each iteration what we are going to do we are increasing the value of count so after each iteration what will happen this value of count will increase by 1 and so when we completed our fourth iteration the value of count becomes 5 and then 5 then the value becomes 5 then this condition will return false and then this condition when this condition written Falls this while loop is going to terminate okay now let's come to using IF else's statement so basically what happens and if as a statement interpreters look for this condition if this condition returns true what will happen this part is only going to execute okay and else part is not going to execute okay so interpreter is keep skip this part if this condition is true so let's say we assign I equals to 10 and this here we have mentioned a condition I is less than 20. so let's see what happens as we know what will happen because this condition is going to return true so this part is going to execute okay but what if if I change the value of I to 30 or 60. then the else part is going to execute why because this condition have written as false okay and why it returns false because value of I is 60. 60 is higher than or greater than 20 okay but here we have written 60 less than 20 so that's why we are going to get a what we are going to get we are going to get false and when we get false this else part is going to execute okay I hope you understand now let's see how this if alif works okay what I want to say and if if L if statement so basically let's see how this alif if alic statement works okay so basically what happened it's similar like uh we have written or if you have studied about else if in C language if you study about this logic in C language this like this logic is similar here also but in Python weary instead of using LC we are using alif okay no let's understand is it's execution okay so basically what happened uh we use multiple conditions okay so if this condition which belongs to if if returns true then what is going to happen if this condition is true then this part only this part is going to execute and the rest of the part is going to terminate okay but what if this condition for got false and this condition got true in this condition what will happen this part is going to to execute okay only this part L If part and what is with this both condition got false then this else part going to execute okay so let's see this practically okay so let me put the value of I is 10. so in this condition what we can get the output we are going to get this one okay why because we got this condition okay if I put something 16 then what will happen we are going to execute our interpreter is going to execute this part because this condition got or true okay what if we put something like okay this condition never going to accept it else okay so let me write here something equals to 20. at this time what going to happen at this time this part is going to happen Okay Run Okay executed why because these two condition is got false why because value of I is what value of I is 60 so this condition will return false then after interpreter search for this condition and this condition also got false so when this two condition got false what will run this else part okay so I hope you understand about all this concept and so see you in next lecture where we are going to create number guessing game thank you welcome back friend so in this lecture we are going to develop number guessing game using python so let's begin so I have already written some tasks which we need to require to achieve to achieve our goal okay so let's do let's achieve our task one by one so we will we will reach to our final vote which is number guessing game okay so first what we need to do we need to import random and time model okay so for importing whenever we want to import any module just we need to write what import keyword okay so we write import keyboard and then uh name of the model which we want to import okay so we want to import random so we are going to write random to that I also want to import type so let's copy this again so import sorry import time okay so first task was complete we have imported random module and time module now second one second task was that create a random number from range of range between 1 to 100 okay so to create a random number in between range 1 200 what we are going to do so basically we are going to use random range method okay so let me write this first then we will understand it so basically what we are doing I was creating a variable n in which we are going to store our unique or random number okay so first of all I'm going to create basically what we are using to create a random number we are using random module and in random model basically we have an an method known as random range okay so basically what random range do random range gives us an uh what I say a unique value in between given range okay so we are using this matter random range method so let me write this ing range okay and as an argument we have to pass two value okay so first one is starting range and from second argument was ending range okay so basically what we want we want a range between 1 to 100 okay so we have given the range here so this line basically what this line to The Interpreter hit this line interpreter will get an uh assign a random number in N okay now write a welcome message so so let's write a welcome message so let me write print so this message is going to be as shown as a welcome message okay so let me well write a welcome to the number game okay number guessing it okay now give two second delay so basically what we want uh we want that whenever user execute this code so user get this line welcome to the number guessing game and if after this line our program got delayed to second delay or we can say we want our program to stop for two seconds for that we are using time module okay so time model have a function called sleep so basically this function what to if I put 2 here so basically our program is going to for sleep for two seconds okay if I put 5 then our program execution is going to sleep for 5 seconds okay so this argument this which argument will pass it's depend okay so let me write two so we are going basically what will going to happen when we put two here as an argument about execution of the code is going to sleep for two second okay now take an user input to enter a number okay so basically what we need is we need a guess from the user okay for so user is going to give us an input for taking input we are you always use input method so let me write uh so basically what we are using we are using input method to take a number okay so let me give a message to the user database number guess our number okay so user will guess a number now input will return us a value in form of string okay always remember when whenever we use input it always written that input in form of string so basically we need to convert its type because we need an integer number okay so we use typecasting here okay so this input will give us string and then we'll convert that string into integer and after in converting the string into integer we are going to store this value in a variable which is guess okay so I have created a variable guess okay so I hope you have understood this execution how it's going to work now so the main part or the main logic starts here okay so whatever what is our task use while loop and create a condition which execute while loop till the both number not become equal okay so basically what we are going to do we are going to use while loop here okay so I have to create a condition which gives basically what this condition to this condition always check okay so let me write n is not equals to guess okay so whenever this condition written true this Loop is going to execute okay and we also want this because we want that this Loop will execute again and again until our condition this condition is not going to return true okay no so they've already covered this part now let's talk about next task though so our next task is what so if gas is a smaller than n okay so we need to create an condition here and that condition is what so basically we want what we have we are going to use we are going to use if condition if statement okay so let me write if guess is less than n okay so whenever this condition occur we are going to print that the number which user has guessed is too low which will give user an idea that he has to or she has to select a higher number than this one okay now let's give another chance to ask to user to guess a new number okay so let me write this other one again yes equals to int input and input let us write that guess again okay because the number user has guessed is smaller okay so guess again now after writing this code what is our next task our next next task is if guess is greater than okay so if gas is greater than what we need to do so let's use alif okay so alif alif is basically else if okay but in Python we don't use else if we use alif okay so LF guess is greater than n okay so for this we are going to print and what and message which is which is going to say user to high okay and after getting this message let's give a user in another chance guess is equals to int input off and let's write okay second okay so basically what is going to happen here uh we are asking user basically we are asking user a guess okay when user is going to give a number then we are going to compare it okay so if they are not equal then this body is going to execute okay for first and then first we check if the gas is less than n then we are going to print too low and then again we are asking user to enter a guess his guess again okay after that what we are doing is we are again checking it if gas is lower or greater than n then we are going to print the message too high and we are giving an another chance to user to guess again okay now if gas is equal to n terminate the value okay so whenever you have to terminate any Loop we use break statement I hope you know that okay so we are going to use else part else statement in any LG statement we are going to use break okay now what is going to happen whenever if User make a guess and which guess is for example if guess got equals to what and then it is going to be break okay and so this task we have completed here okay and now let me write a final message okay so final message is what so let me write print this final message is going to execute When what when the guess end the random generated number is going to equal okay so at that time this gas is going to be uh this basically this final message is going to be printed so what we want to print we want to print some Stars and then in between the two stars we want to print you guess to the right against it right later okay finally we have completed our task now let's run this code okay so here you can see welcome to the number guessing game guessing number so let me guess 50. so 50 is too high so let me guess 30. so 30 is too low so basically what we can conclude that our the number which we have to guess is less than 50 and higher than 30 so let me guess 40 okay so 40 is too low again it means our number is going in between 40 and 50. so let me write 55 okay so finally we want okay so number which we have to guess is 45 I hope you understand this logic and welcome back friends so in this lecture we are going to add some more functionality in our number guessing game like user have only five attempt to guess the right numbers and after each case if user is wrong user will get a message which tells him about number of attempts left and if user used all its attempt and not guess the right number then user will get a message bad luck try again okay so let's core this functionality in our code Okay so but before that let me copy our code and paste it into new cell now so basically what we have to do we have to give user only 5Ks five attempts to guess okay now for that uh what we have to do let's first print this message to the user so user will know get to know that he has only five attempts okay so let me write it here uh you have you have only 5 attempts to guess no okay so attempts to guess okay so this line will help user to understand or that he has only five attempts to guess now I am using here slash and basically what is this slashing is a new line character okay so basically this new line character is what going to do whenever interpreter get this new line character it is going to switch the line and print this line okay now as you all know we are using slave function because we want two second delay in our code execution okay now so okay now for our main functionality which we are going to add is that user only have how many guesses attempt only five okay so for that we are using a counter variable okay so basically what counter variable is going to do counter variable will help us to count the user number of guesses okay so let me create account variable so write count let's assign it one okay so basically why we are assigning it one because user already have guessed one time okay no so whenever or wherever is going user is going to count or guess the number we need to increase the value of count by one so let me write count plus equals to 1 okay and here is also user is going to count so let guess so let me increase right here count plus equals to one so whenever user is going to guess we are going to increase the count by one okay now and one more thing we also want that whenever user gets the wrong number user will get a message so let me print that message okay so basically what message tells this message will tell basically what that user have this much amount of left okay so you have so for this we are using placeholder okay and format method okay so you have now basically what this is going to do is whatever message uh the value we are going to give it here it's going to print here okay so let me write here 5 minus 2 so why we are writing 5 minus count let's understand let's understand this user have already guessed a number okay which is too low okay if this number is too low then this message is going to print and for that time you this value of count is 1. so 5 minus 1 is it will return 4 and this 4 is going to print here so basically what message user will get that you have four attempts left I hope you understand how this format is working okay so let me undo this now let me copy this line because we know that we have to print this line when user guess a number too high okay so whenever user gets a number which is high higher than a guess number then what is going to print too high and after that user will get this message you have this number of attempts left okay and after that user will get a message case again okay now let's run this code I think we have achieved but before running this code executing this code let me write one more thing and which is now basically write what is going to happen here we need to use if it's a statement because this while loop which is going to terminate on two condition okay let me tell you okay I have never mentioned this condition and I have to mention this condition okay so this is the condition is when count is less than five okay so basically we are using logical operator here and because we want this Con if these two condition is true then this Loop is going to execute if what and if we got any of these two condition false this Loop is going to terminate okay so basically why we are using this condition because we only want to give user 5 chance or five attempts to guess the right number okay so basically what will happen after each guess user will made what we are going to increase the value of discount okay so whenever user will guess a number we are going to increase the number of count by one okay so what is going to happen whenever user used all its five attempt this condition will return false and when this condition returns this Loop is going to terminate okay so I hope you understand what why I write this condition here now I think we have um okay so we have created and now let's discuss why we need if else here okay so basically why we need if else here because this while loop depends on two condition okay and this while loop is going to terminate on two condition and the first condition is what when user gets the right number okay when user is the user cache and the number which is randomly generated become equal then this Loop is going to terminate and the second condition is when the number of count or we can say the number of count equals to 5 or when user used its all gases okay then this condition will terminate the loop so for that we need to write here okay so whenever this Loop is terminated this line is going to execute and for this line we need to write a condition so if n equals to equals to guess what will happen they are going to print this line okay that you guessed it right and if user gaster user used it's all what I say all attempts so this line is going to print what line that bad luck try again okay now I think we have achieved all our goals now let's run this code so we get a message welcome to the number guessing game you have only five attempts to guess okay now guess a number so I hope let's check okay so before playing this game let's check this game okay so now let's check how many attempts this game will give to the user okay so for this I am going to make same guess again and again for example 10. so he tells me that this games tells me that you guessed to the number you have guessed which is 10 and you guessed your guest number is too low and you have four attempts left okay now let me guess it again 10. so now you can see here you we will you will get the message that you have three attempts left okay let me guess 10 again then you can see here we get a message that you have two attempts left let me guess 10 again then I got a message that you have one attempt left okay so we got it now so this game is going to give user only how many attempts five attempts okay so we have achieved this functionality now let's play or run this game and this time we will win Okay so let me guess the number it's 50. okay so 50 is too low so I think it's 2i so we can as assume that our number is lie between which number we have to find is lie between 50 and 80 okay so let me write it again yes it again so 50 okay so what we can it's maybe 70. 70 is too high it's means let's try 65. 65 is too high let's try 60. oops I'll lose this game okay so I hope you know I hope that you understand that how this game work and how to create this game and I hope you understand the logic behind why we use this counter variable and why we use this condition so welcome back friends so in this model we are going to learn how to create two-player tic-tac-toe game okay so before learning this game let's play this game and enjoy okay and after playing this game then we are going to learn some basics of this game and then we are going to create this game okay so let me run this code okay so here this is our basically tic-tac-toe grid okay now basically there are two players okay first one is X and second player is o so the this time this is the extern Okay so xf2 put some position okay or place so if x want to update this position or X1 this position okay so he has to put he has to write he has to give that poor place is seven so here you can see we got X here now it's second player turns okay which is O So o want this place to be occupied so choose 9. so now you can see that our grid is going to update after each value we are going to choose or it's it play so now let me write this one so x ray have mentioned here now what is going to happen now all need to stop this stop X to winning this game okay so he is going to put o at place 4. okay now it's extern so X is going to take three Place third place here and now oh got confused because why because if o take this place then X is going to take this place and X is going to win if o take this place then X that takes this place after host turn and X is going to win so o has no choice so who is going to write five and now it's extern so X is going to write or take second position or second place now we've got this we get a message that games game over and X4 okay so this is how this Tic Tac tool works okay so in upcoming lectures we are going to learn some basic concept or basic logics of python and when when we understand all those Logics then we are going to merge all those logics and we are going to create this tic tac toe game okay so till then take care and see you in next lecture welcome back friends so in this lecture we are going to discuss about some basic concept which we are required to create tic-tac-toe game okay so first of all let's understand what is python dictionary okay so in the python dictionaries are used to store data values in form of key value pairs okay so basically uh let me in this let me clear you that whenever we create python dictionary we always use item or restore item in form of key value pair okay so basically what is key value pair basically we use what we use colon to separate the key value in left hand side we mentioned keys and on the right hand side we mentioned values okay when we create dictionary you will get to understand this thing very clearly okay now and if we talk about what is dictionary so basically dictionary is a collection which is ordered changeable and does not allow duplicates okay so basically this what is dictionary so basically dictionary is a collection which is ordered which is changeable you can change it and but one thing is that which makes dictionary very useful that uh it does not allow duplicates values okay so let's see how to create dictionary so whenever you have to create a dictionary you just need to uh first you have to mention uh what I said mention a variable for example if I have to create a dictionary I am mention a very I have created a variable known as dictionary one and now I have a going to use curly braces okay so to create dictionary we always use curly braces and in this dictionary in this curly braces the give item in form of key value pairs okay so let me create additionally for example let's name this dictionary as a dictionary five and let me give some values to it okay so basically let me give first one and this is basically this is our key one and the corresponding value of 1 is well okay integer form then we use comma to separate the items of the dictionary so let me create another item okay which case is 2 and its value is 2 okay so I hope you understand that how to create dictionary and how to add items in it okay so basically I what I have to do is I have to mention here a key so let me 3 colon and the corresponding value is 3 okay now this is how you create a dictionary so let me print this dictionary so when we execute this code you we will see how our dictionary looks like so you can see when you print the dictionary five you will get one in form of this is the key and this is the value if we talk about this item this is the key and this is its value if we talk about this item so this is 3 is a key and this 3 in form of integer is an item okay now so basically why we are learning dictionary concept because [Music] when we use tick tick when we run or when we create this tic-tac-toe game we are going to use basically this dictionary to store the position of X and Y or X and 0 okay let me show you what I was talking about so basically I was talking about this concept okay so we are going to use dictionary to store the value of these positions okay so basically if you have gone through this article which I have written this here so basically when we play Tic-Tac-Toe game we use 3 by 3 x grid okay now let's go to again warm-up exercise okay so here we are going to use dictionary as you can see here keys in are in form of string okay so here's I have written a seven but I use quotation mark so which basically makes this 7 Alpha as a string okay and all the value corresponding to the keys are white space so basically the values which you have seen here are the white spaces okay so let me execute this code what if if I write something like that uh okay we will discuss this later on okay this concept now learn how to apply Loop okay so whenever you have to apply Loop so basically generally we use for Loop okay so let me write for I in or let's say item in okay one more thing is that whenever you are going to apply loop on dictionary okay so let me write the dictionary five and let me just print the value of okay key in each iteration okay so when uh let me clear this one thing whenever you are going to apply a for loop on a dictionary all the evaluate this return okay at this condition the value we get is only the key okay of that dictionaries so let me write this okay so when we execute when I execute you will understand so here when we applied this for loop on dictionary 5 what we get each iteration we only we get what the value of 3. the name of the key which present which are present in the dictionary 5 okay I hope you understand about this now how to access learn how to access the dictionary what I said dictionary is items okay so to access dictionary item we always use what we always use Keys okay so let me write this basically let me correct this items value okay so whenever you have to access the items value of a dictionary how we could basically we just write print okay and then we mentioned the dictionary name so for example here our dictionary is dictionary one dictionary zero one and then we use square brackets and write or use key so what this code is going to return this code is going to return us the corresponding value of this key seven okay so let me execute this code you will get that we got G as same as just imagine just let me write if I mention here something like 2 or 3. so you can guess what value we are going to get yes we are going to get C you can see this okay so this is how we can access the dictionaries items value okay using key name okay now how to create empty list so creating empty list is very easy okay you just need to mention a variable okay variable name here I have written a name board underscore keys and to create empty list you just need to write what this is square brackets okay opening square bracket and closing square bracket so basically what this code will do this will generate a empty list okay let me write this okay so when we print bold underscore keys so what we are going to get we are going to get I empty list what if I mention here one then we are going to get a list which has one element okay so basically let's understand how to create empty list to a create empty list we just write a variable name and then we mentioned use square brackets okay no no no welcome back in home of exercise of tic-tac-toe part two so let's learn that how we can append the dictionaries Keys into a list so basically we have generated a empty list as you know here as you can see here basically now what you are going to do basically we are going to use the board additionally okay so what we are going to do basically we are going to apply the for loop on the board the board dictionary okay so basically the board dictionary is what let me see so here this is our the board dictionary okay so what we are going to do basically we are going to uh going to apply the for loop on this board Edition let me copy this so we will understand me better okay so basically what you are going to do is basically we want to copy or we want to append all the keys of this dictionary the Bold dictionary into our this list okay so how we are going to achieve this so basically we are going to apply the for loop on this dictionary the name board okay and what this dictionary is going to return is we are going to apply this uh for loop on this Visionary so basically each iteration we will get the key value so basically this key variable is going to hold up the value of key one by one okay so let me write okay so basically what is going to happen here we are just going to apply the for loop on this the board dictionary and when what we are going to get we are going to get in each iteration we are going to get these Keys one by one into this key variable okay and when we get this key values in this key value key variable then what we are going to do is we are going to append we are going to perform append method okay so basically this appendic method is a method of key basically it belongs to list okay so basically this append method is a method of list okay so basically what this append method will do this append method will append or we can say add the given item in the list at the last position okay so let me see okay so let's run this code and you will see it when we run this code we will got okay let me print so we got clear ID so let me print here okay so what we are going to do basically we are going to print here and each print basically what's going to happen here from each iteration we are going to get to know how our this board keyboard underscore keys list looks like okay so words underscore keys okay so let me execute this so you can see this is our empty key oh sorry empty list and from each iteration what is going to happen basically in each iteration what is going to happen is we are just going to insert or add or we can say append the value of key which is the dictionary key is well okay so basically what we are going to append or add in this list the value of the key names okay so you can see for each iteration what is going to happen in each iteration the value of the key or we can say the name of the key is going to insert at the last position of the list in each iteration so I hope you have cleared this concept okay now let's switch to the next concept okay so learn how to print multiple message or string or variables and Message Board together okay okay so this is very basic thing so whenever you have two messages or the two variables to print for example a equals 200 and b equals to 200 okay now what you have to do you have to print this value is okay so basically you have multiple values okay so so how you can print it so basically generally you can use a comma and B so when you execute this you will print this two values of the map okay values or the variables value of these variables A and B now what if if you have to mention some message okay here like for example value of a colon a okay so basically what is going to happen in this time when you execute this you will get this message printed and after that printing this message interpreter will print the value of a okay looks like this value of a colon 100 okay what is if you have to put print multiple uh well for example so multiple messages like this and values okay so how you can use this print so we you you can write this like value of a then call in and then what you are going to do variable a then you can again use comma and again you write the message that which is value of p together you can use colon and the okay so yes this is it now when you execute this code you will get this message in this format okay so this is how you can use or you can print multiple messages and variable in one single using print okay I hope you understand this okay now learn how to create tic-tac-toe board okay or grid of three by three so basically we are generally using what just using some logic of how you can print okay so basically we are just printing what let me see we are just printing a white space here okay so basically what is our task we have to create this kind of code okay this kind of okay and how we are going to achieve this we are going to just use some lines like this some Dash using Plus Dash okay so let me see how let me understand uh let me explain how to use this okay so basically what we want in first line okay we need a white space so basically what we have done we give a white space in as a string okay we created double quotes or you can either use single quotation mark okay so here I use same double quotation and I give a white space so basically what will happen when you write okay let me understand uh let me explain this from the very basis so basic okay it's something like this what is going to print obviously it's going to print a wide space okay here this is the white space rub now what if if I want to enter this line okay so how we are going to do this either you can use comma or you can use plus sign okay basically why you are using plus say because we know that the concept okay whatever will happen if we use this plus sign in between two string so let me explain this a and plus b so what is going to be basically it's going to concatenate these two strings okay a b okay I hope you understand this so basically what we want to concatenate here a white space and a parallel line okay now so basically we want to print this so you've got this okay now if I have to also if I want to add a white space again so what we can do we use plus sign and use double question marks and give white space and if I want another line then why how we are going to do is double quotation marks and um not this time white space we need this row this okay and otherwise space okay so this is how we have created the first line no what if I want to create a new line about let's try learn how you can create this line okay so you just need simply write print then afterwards what we want basically we want a dash okay so we will we are going to give it a dash then after that Dash what we want you want the plus sign then we are going to just use this plus sign for concatenation now now we like to either we can use double quotation or a single quotation here and then when I we are going to write plus okay now we are using quantity Plus for concatenation and we need Dash then afterwards we need plus sign and then we need Dash Okay so for that what we are going to do we use corn here we need a dash okay so we Dash then we need to write Plus for concatenation then we are going to use double quotation marks and then write Plus then again we try plus and this time we need what we need Dash okay so when you execute this code you will get these two lines okay similarly if you copy paste this all cook you will get what these two lines okay so basically we have generated we have created four lines we need another one so this is how you are going to print or this is how you are going to create our what I say good okay three by three x by 3 okay grid now and why we are creating this grid because when we going to play this game tic-tac-toe so we need a grid Okay so for this grid for that grid we are going to use this concept okay we can either understand this concept by using uh so let's use something import that's okay so let me import time okay if you uh so let me write this here I basically what I am going to do we are I'm going to use that sleeve function okay let's leave functional what this function will give us that say function will give us some amount of delay okay and that's amount of delay basically the amount which we are going to mention it so for example if I want to second delay the how I am going to write this time dot slip and brackets I'm going to give it two okay and let me copy paste this all here so you are going to understand that how this is uh this box is going to print okay let's execute this you can see what's what we got okay module time is not oh QQ we made a spell mistake here now you can see this is the first line this is the second line print then third line then fourth line and this one is Fifth Line okay and our grid is ready right now let's move the next thing so learn how to use dictionary item to print okay so now this time what we are going to learn that how we are going to print this dictionaries item okay because we are going to use this dictionary to store the value of these positions okay so whenever user put here x for example in this box if user put X and in this box user put 0 so we are going to update our dictionary according to that okay and then we are going to print this grid again and again so we will get the value of uh we will get to know that what position has taken and where you have to where user have to use or need to put his chance now so basically what you are going to do is we are going to learn how we are going to use dictionary items to print okay items value let me correct this items value oops so for example if I have to print this x okay the value basically this value is corresponding has a key okay which key seven so I have to write here okay what I have to write here I have to write dictionary 0 1 square bracket and then in this Square packet I have to pass key 7 so let me run this code and you will see something okay so here we have updated that this way value of x what if I have to use what I have to print this value okay corresponding 9 where I have to print I have to print here so where I have to make changes I have to make changes here okay so let me write this dictionary 0 1 and then what I have to do is I have to have to write the key value which I want to print here so basically I want to print nine so let me write 9. okay so you this is how you are we are going to use this concept during the creation of tic-tac-toe game okay okay let me explain uh what if if I want to print this uh all the values okay in this dictionary so how I'm going to do is I am going to write in here okay so dictionary 0 1 and corresponding key is corresponding so we are getting what basically this is the key 8 is holding the value while the space okay we are getting white space okay one so let me write this all here and we are going to print this okay so let me write this so dictionary one and then square bracket and then I am cool I have to write so why I am writing for because this position belongs to 4 and the corresponding the corresponding to this key what value we have X okay now just let me write this thing so just may I will I'm going to copy it and paste it where I have to write it so instead of 4 I have to write 5 and at this position I have to write what I have to write sex okay similarly here I have to make changes in this position I have to write 3 for this position I have to write what NES yes to and for this position I have to write what okay when I execute this you will see this is how we are going to update our tic-tac-toe board in each iteration okay so I hope you understand that how to access the value of dictionaries items using key okay I hope you understand this now Welcome Friends in this third part of warm up exercise of tic-tac-toe so this part is going to be very important because in this lecture we are going to learn some important Logics which we are going to use in our game so let's start so our first logic is that we are going to learn how to check empty places in tic-tac-toe 3 by 3 grid and insert the value okay so actually if you look at the above cell which we have discussed in last lecture you will find that at the time what we are doing is basically we are hard coding the values and printing it okay so basically what we are doing is we are putting some value here and we are printing it okay so if I doesn't want this x to be here I just execute this and this x is gone if I want the X here then I have to put X here and execute this and I got X here so basically this is called the concept of hard coding hard coding means doing with your hands or your own without doing any using any Logics okay so now let's understand about what we have to learn in this thing okay so basically what we have to learn that how to take input okay input position from the player and check the position is empty or not if we found empty position then we are need to put X or o at that place okay so basically what we have to do is you can see here basically when user give you something give you a position okay whatever what happens when tic tac toe game Run so basically our game wants and position okay where you have to put the X or o so basically what you have to do you have to just take the position from the user and you then you have to check in this dictionary that this position is empty or holding some value for example if user gives us 8 okay so we take that add position and search in this dictionary with using add number eight key okay and then we will find if this place is empty okay means white space then we are going to put the value here if this place is not empty for suppose this placehold a value oh okay so if this place is not empty then we are going to do what we are going to send a message to the user that that place is already taken select another position okay I hope you understand that what I am going to say okay now so let's understand how we can do this okay for that what we have to do we just need to use if else statement okay so basically when we use if else statement what we are going to do here okay before using IF else statement let's understand how we are going to take the value from the user so basically we are just using print function where you we are going to print the message okay and after that message what is going to happen we are using input method okay so basically when user gives something for example uh any position what is going to happen when user enter the position or a number or a place okay so what is going to happen it's going to store in this variable move and what is going to happen when we are going to check this condition so basically what happens for example if user gives us a place let's say 8 okay so what is going to happen this 8 is going to be initialized or stored in assigned to the move variable and then what will happen when we check this condition basically what you have what we are doing here we are just checking that dictionary one and the respected key which user has given us okay so let's say dictionary one and this move will has value 8 so if this condition true means if dictionary 1 key 8 has empty place or white space then what is going to happen then this going to happen What then dictionary 1 move means 8 is going to hold this value okay so this value is what this value is turn and turn is basically in this code basically we have assigned this turn variable equals to X okay now let's understand and let's execute this code you will understand more okay when we execute this so let me execute this so when you execute this code what we are going to see we are going to see grid why we are going to see this grid because we have written here okay return the code to see the grid okay now basically we have declared a variable called term okay which is X so what we are going to use basically this execution is going for player X okay so when X so basically what message we are going to get here what we are using we are using concatenation okay so in print we are doing concatenation what continuation we are doing basically we are writing a first message it's your turn and the value of turn basically the value of turn is X and move which move to which place okay so basically this line is used to ask the user that it's your turn X and move to which place okay so for example if x want to move this place here okay where here so how he can move he just need to enter eight okay and then keep print or he gives it what will happen when you print this dictionary again let me print this code you will see the update in the dictionary okay so you can see what this happened here we put the basically this code will execute perfectly that use computer is asking for it's your turn X move your place then user gives a value 8 then what happens this X comes at the place of 8 okay now how we can change the players after every move this move is only for X okay now we have to do what we have to move the we have to change the move every time okay so how we are going to do this for that we are going to use for Loop okay let me write this so let me copy this and then you will understand how we are going to use okay so now for this I am going to create a for Loop uh just wait okay so we are going to put whole this code into formula and here I am just going to execute this for Loop for three times only or four times let's say so for in range actually just I want to explain you how this for Loop executed okay so just we actually we are wanting what we have wanted that just we want this Loop to execute for four times okay now what is going to happen let's see uh let's change some value of this dictionary so where is this dictionary okay let me copy this thing so this is our dictionary and this is let me execute this then you will understand so basically what changes we have made we empty some spaces here only position 7 position 1 has X and position 6 and position 3 has o okay now what is our message is asking our message is asking it's your turn next move to which place okay so if for example X select nine place okay so 9 basically is this place okay so that let's see what will happen okay so you can see here we got X here okay now what he's going to do okay we are not changing the position we had some mistake here and what mistake we have done okay this line is not executing actually why this line is not executing if turns is equal to X then o so what is your turns okay let me change this thing basically what is happening we are assigning each iteration for each iteration we are assigning this term equals to X that's why we are got getting this problem okay so let me cut this code from here and put it here okay now when we execute it it will execute perfectly okay so let's see here just wait a minute okay this is our grid now it's external so X select nine when you you can see in this time your message got changed okay it's your turn 0 or 0 move to which place okay so if o wants to move this place okay so then for this place what he has to do user has to write four and then you can see easily what will happen here o comes okay now it's booster it's X turn so X has two puts for example here okay if x wants to put X at which position at two position so he has to write two then X will come here and now what is happening here we got another message which tells it's your turn 0 or o move to which place okay so now for example if user if o wants to move at this place which place is fifth then user have to put basically why this for Loop basically why execution of this code is stop because we use for loop with range 4 so basically this fourth this for Loop is only going to execute for four times okay now let's understand the logic behind how we are changing the turns here how we are changing this message again and again so basically what is going to happen here initially we have declared the turn is equals to X okay so basically the value uh basically what will happen the turn variable has this value okay now what will happen after the execution of this thing this will print then it is going to be print it's your turn okay then right now the value of turn is what x so here what we are going to get we are going to get this message it's your turn X move to which place okay now user enter something let's discuss with this example okay so now user has entered nine okay so when user enter 9 what will happen move will assign to the 9 and what is going to happen we are going to check in dictionary one that move the key move is empty or not if key move is empty okay so he basically this key basic belongs to move belongs to nine so if key Nine is the corresponding value of K9 is empty or white space then what is going to happen then that dictionary 1 9 is going to assigned the value of terms which is X now after what is going to happen after this part after this part this thing is going to happen so after this execution what is going to happen if turns equals to equals to X if turns is equals to X then what is going to happen then this condition is written true then turn is going to assign to the new value which is O okay [Music] this is how this execution works in next time what is going to happen this is only if this happens in first iteration in next iteration what is going to happen in next iteration this whole thing is going to print again in this time as we know that right now the value of turn is becoming is have is become 0 or o so now what message we are going to get it's your turn 0 or 0 move to which place okay as you can see here after X what we got we got this message it's your turns o move to which place now what is going to happen if user enter 4 then same thing is going to happen again that this using this condition we are going to check if the position if the key 4 is empty if key 4 is empty then we are going to initialize that key for in dictionary one with the value of 10 and the year for this iteration the value of turn is 0 okay or or we can say to that what will happen then same thing happens if value of x or value of turn is what for this iteration what is the value of turn is value of turn is right now it's O Okay so this condition is going to false when this condition is going to first then else part is going to execute in X part we have written that turn is equals to X okay so now what is going to happen now the value of turn is going to initialize X okay this is how this iteration work again and again and now this for Loop execute Vector value of turn is X okay then whole thing will print again then it will again Ask it's your turn X move to which place as you can see here in third iteration what is going to happen this chart is going to print then this is this message is going to print it's your turn X move to which place okay then you enter your user enter 2 and what will happen add the position to this x is going to be print and next move what will happen for next iteration what is going to happen the value of what the value of turn becomes o and then this message is going to print again it's your turn or move to which place I hope you understand this logic okay now let's understand how to check multiple condition if using if statement okay and learn how to compare multiple variable so basically why we are using this so the basic the reason behind this we need this because we have to check each and every possible condition which can occur during this game and we also have to declare the winner or Thai condition okay so basically there are multiple condition is going to be happen here let me see okay just wait a minute so basically what is going to happen right now uh let me say you something so basically whatever is going to happen we have to check the multiple condition each time okay what are the possible condition which can make any user win okay so for example if x occupy this line then X is going to win okay if x occupy this line then X is going to win if x occupy this line then X is going to win if x occupy this line then he is going to win okay and same task is going to be uh we have to check this same task for o also okay if over occupy this Lane then o is going to win or occupy this line then he has to win if occupy this diagonal then he has to win if occupy this line then he has to win so basically what you have to do we have multiple conditions to check during the execution of Tic-tac-toe and we are going to check each time okay for each iteration after each and every push position if user check or user select then we have to what we have to do we have to check for each and every possible condition for that what we are going to use for that we are going to use if alif statement okay so first of all let's learn how we are going to uh what we can say find that these values are equal okay so how we are going to do this as you can see I have created a dictionary one okay now in this in this dictionary one what you are going to see here you can see the key 7 key 4 and key one has what same value which is X okay and if you look at this K 6 and 3 it has same value which is let me remove this one so okay now this is our dictionary okay now let's understand this concept then so basically what we are going to understand in this we are going to understand how we are going to see just wait a minute let me commentate those okay so basically what we are going to see how we are uh use how we can check multiple condition in if statement okay so this is the best way to write if you have same values if all the variables have same values then you can write this either you can use then and logical operator or or logical operator but for this tic-tac-toe it doesn't require all those things Okay so free so for this we just need what we just need here we are going to write this positions in dictionary 0 1 key 7 in dictionary 0 1 key 4 ending dictionary 0 1 1 key okay so we are going to just check if these all values are equal then what is going to be print then this line is going to be print so let me execute this if we execute this code then you will find out that what is our output going to be that key 7 4 and 1 has same value okay why this has same values because this condition is going to return true why is going why this condition is going to return true let's see in dictionary that we already know that the 7 4 and 1 is holding a same value which is X okay now let's see something here what if you have we have to check this type of diagonal let me increment in the house okay now let's understand see this what if we have to check this one like this diagonal okay what we are checking right now this one let me show you the conditions here conditions are dictionary 0 1 9 key sixth key and third key so you can imagine this is ninth key this is sixth key and this is third key so we are just comparing this okay so what we are comparing if this all values are equal then we are going to get this message and if these values are not equal then we are going to get this message okay so let's see what message we are going to get before that let's see what is our dictionary told us okay so you can easily see basically you can see the value of 9. this key 9 is holding the value empty space okay or white space okay and here the value or key six and key 3 is holding value o right so when we execute this code this four line of code then we are going to get what then we are going to get something called basically what will happen this else part is going to be printed let's see let me execute this code when I execute this code I will get this key 963 has different value okay I hope you understand about this what if I put if we put something like that if we put o here then you can imagine what is going to happen you can guess let me execute okay so at the time we are going to get this message what key 9 6 and 3 has same values you can see here key nine six and three are same values okay what if I put 0 here uh instead of o i put X then again we are going to get which message else part why because here dictionary at key Nine this value is X and this value is O and this value is O so here we are going to get an false return and when this condition for return false we are going to our interpreter is going to execute this line okay now let's move to another one so whatever that part is um no so but we compare the key which one okay now let's let's check this condition okay we are talking about this condition how we are going to check this condition the same way we are just going to write dictionary one is dictionary one key eight additional equals to equals to dictionary one key five and equals to equals to dictionary one key two okay so this one is X position this one is fifth position this one is second position right now for that what we are doing if we look at our dictionary one what we can find you can see here in dictionary one you will find out that all these values 8 5 and 2. this case 8 5 and 2 Keys holding white space is okay so if you find out if you run this equation you will what we are going to get let me run this if you run this kind if statement you are going to get this word you are just going to print this line that key 852 has same value okay which looks good which looks KS this key 8 key 5 and key 2 has same value but basically in this tic-tac-toe game what we are using we are using white space for holding empty spaces okay and why we are using white spaces let me explain you this thing so let's see here our where is our code okay let me see okay this is our board okay in the Box okay so this is our board okay what if if I don't mention here you can see to print me this kind of board I have to use white space if I remove these white spaces then what is going to happen this structure is going to be destroyed okay you can see here for this purpose what we are using we are using for empty space we are using white space for showing that this place is empty okay if you remove this all these spaces then what is going to happen the structure of this board is going to change this is become a different thing okay right so for that purpose we are using white spaces okay I hope you understand why we are using white spaces in okay now so how to deal with this thing basically if you check this condition then this condition is going to say that all values are equal and if this all values are equal then he will maybe what will going to give us is going to say that this person is going to win okay but basically these are all our empty places then how to deal with that so for how to deal with that we have to use this thing let me write this so basically what we are going to do let me comment it out so for that we are using this we are adding this condition into this condition so basically what we are doing is we are using using this not equals to White space so basically what is going to happen here this line is going to first what this condition if we talk about this condition is going to check this values if these are equal then they are going to check if all values are equal to each other but they are they are not been equal to white space okay so if all these values are not equal to White space then what going to be happen then this value is written this condition written true and then when this condition return true this line executed okay or what if this all values are not equal to or equal to White space when this value this thing happen then what will happen this condition will return false okay and when this condition written false this line is going to be executed okay so let me execute this code you will better understand this so let me this series okay oops we got something called just wait a minute now you can see here we get Force key 8 key 5 and key 2 has white spaces okay why this is happening because we are using this condition here basically this condition is what is not equal to White spaces if they are not equal to White spaces then what is going to happen this slide not going to happen for example let me change the dictionary again and then we will say it for example here we remove the yd space and put 0 or o in place of this so I removed this white space and I put o in place of this okay and then if I execute this what is going to happen you are going to get this message that 852 has same values right I hope you understand about this all okay now the last thing is okay so last thing let me write let me comment it out this now okay so last thing what if we have to understand yeah now to check how to check position nine three and six have same values but all values are not quite space okay so how we are going to check just we are going to put something called this condition is uh which is what not equals to white space okay when you put this condition you will get this value okay I hope you understand this concept now let me explain you how to create a function so basically to create a function you just need to use Dev keyword and you have to mention a name of a basically a name of a function for let's say if I create a function name game and we use parentheses to declare or Define a function then we use colon and after an indentation we start writing the code of this basically what code or line of codes we can say which belongs to this function for example let me print hello or you can write light start the game okay one thing is that this is just a definition okay so whenever you define a function and you can execute this code but only when this function is going to execute when you call that function so if you call this function game then what is going to happen then this function is going to execute if you don't call this okay so basically how to execute function is just a way to that you have to mention the name of the function which you want to call okay using parenthesis right so I hope you understand that how to define a function basically it's let me explain it again that we whenever we have to define a function we use Dev keyword then mention a name of the function and then use parentheses and then after colon we are going to write what whatever the body of going to be have going to a part of this function okay so basically if we talk about this function this function has a one line as a body of code which is start the game which is going to print start the game okay so whenever you call this function you are going to get this line let's start the game okay and you can call a function many time multiple times you want as many times you want basically so if I write game start the game start the game for two times what if I mention here something like this for I in range 10. colon so what is going to happen we are going to get this line start the game start the game for 10 times Okay so so you can call any function any number of time you want okay so thank you for this lecture this lecture is going to be so tough to understand but if you have any doubt you can just rewind the video and see it again okay so in next video we are going to create that tic-tac-toe game okay so see you later till then take care thank you welcome back friends in this lecture we are going to discuss about how to create two players tic-tac-toe game in Python so let's start so first of all we need to create a dictionary because in this dictionary we are going to use all the keys as the position or the location of that tic-tac-toe board game okay now initially all the values are basically empty spaces and after each move we are going to update this empty spaces with X or 0. now here comes after that we need to create a function which is going to help us to create what to create or show us this type of grid okay so for that we are going to create a function this function is going to help us okay to print every the board every time whenever we are going to use it after that we need to create a function which have all the game play functionality so let's define a function name game after that we need to create a variable term variable and assign it X where we need because always tic-tac-toe game starts with X okay now let me create a variable count that is used in this variable to count the variable to count the number of moves of both players okay so initially we are going to put this count equals to zero now create a for Loop for range function with argument a because we need to execute player's turn for nine times so we are going to use for loops okay with range and in range we are going to give argument 10 now we are going to use function to print the board which we have created earlier okay now write a message to get a value from the user for that I am going to write a message which tells P tells the turns and ask for the value now after that we are going to use input method to get the input from the user now we need to use if statement to find the empty place on board and put input value move in it for that we are going to for that we are going to use this if statement if as a statement as we have discussed its functionality earlier in the course now what we have to do now we have to use allifist if alif statement to check every possible win condition if player X or 0 has won for that we are going to use if as statement and where we have given multiple condition to check each and every possible winning conditions which came across during the code execution and after that what we are going to do we are just going to check we are going to create if statement to check if either X or OV and for that what we are going to do basically we are going to create a if else statement okay if the count equals to equals to 9 then what we are going to print game over and it's time now change the value of turn variable or the player after every move so for that we are using a file statement this logic we have already discussed in our last section last video now for calling this gain function we are going to write the name of this game function and we are going to execute it so this is how we are going to create tic-tac-toe board or tic-tac-toe game I hope you understand about all the functionalities please recall everything and start playing it thank you and have a nice