 Hello everyone, today we are going to look into some programming aspects of this engineering statistics. So, as we know or as we discussed so far we are talking about various distribution data generated from distributions and if you are given a data we want to see that what is the underlying distribution that is generating this data and all. So, to do this we may need some tools to or mostly the software tools to analyze this data and for that we are going to talk about Python today which is one of the languages widely used in statistics ok. So, we are just talking about Python there are other possibilities like one can use MATLAB one can use R and other languages, but here I am going to talk about Python. So, to begin with we will talk about how to get the things running for this. So, first I will talk about very briefly about how to install and how to set up our environment. So, Python is very easily accessible it is open sourced you can just to go to the python.org websites and just download the latest version. So, here when we try to do this the version 3.10.6 was the latest version and you can choose whatever the latest stable version available when you visit the site you can download that. And here we are talking about installation for windows, but you can follow the instructions given on the python web page to get it installed for if you are using either Linux machine or Mac OS machine. So, once you do this you just to follow the instruction and you let check these options like you need to set this to be set up in certain paths and give access to other users use are like a standard checkboxes you do this and go for customized installation and then maybe the installer ask you to specify the location where we install it either choose a default one or if you want to put it as a separate location just specify your location and once you are done this is done. So, the python gets installed. Now with this you have a python you may just launch your terminal and run your code there whatever you code ok, but often we want execution the code to be more interactive and maybe if we have something like an IDE kind of environment is there then it is better. So, for that we will look for what options we have. One of the popular option is Anaconda and Jupyter Notebook. So, Anaconda is basically a one of the open source python distribution platform. So, it supports maybe other languages also not necessarily python it is like a very comprehensive tool you can use it. When you use Anaconda it comes with many ideas I will come to that, but just let us quickly follow the steps here to get your Anaconda installed and here you can just go to the website of Anaconda click the download and just follow the steps get to get your Anaconda installed. Again it will the installer will ask you to give you the path and it will you have to check certain options choose the options as necessary for your machine and check you need to also be careful whether your machine is a 64 bit has a 64 bit processor or 32 bit processors accordingly you select and then you are ready. As I said Anaconda is like a platform it comes with various ID tools like Eclipse, Ninja and I do not know maybe there are several others, but one of the popular ID is in it for running python code is Jupyter Notebooks and that is what we will be using that is what we will be discussing in this tutorial session. So now once you have the Anaconda successfully installed what you need to do is you need to open your terminal. Let me see my terminal is over or maybe I will just come out of this presentation mode. Now I will open my terminal here and in that I will just simply type Jupyter Notebook and this will open Jupyter Notebook and here Jupyter is an web based IDE. So when you write this Jupyter Notebook it will directly open inside the web browser. Now here in whichever directories you want to write the code or you have already written the code go to that directory. So here the codes that I have put are in this Python 001 folder I am just going there. And now I have a notebook already created Python 1, when you click it will open this where I have already written some content which I am going to discuss. And if you want a new Python sorry a new notebook you can just go here and open a new book here and do all your code executions here. So let me go back to the ones I have already created. So the first thing in any programming languages just to understand how to create variables and strings and Python gives a very easy and intuitive ways of creating these variables and strings. So let us say if I want to create a variable x for which I have to assign a value 2 I have to just write x equals to true. And if I have to create a string of word hello word I have to put it under this inverted commas and assign it to a variable which I would denote it as string 1 here. So let us see how does this work. Now I am going to run this when to run either you can click here or you can use some shortcuts like I am using a MacBook here there my keyboard shortcut is to shift and enter then it will run. And let us see if I want to insert another cell here I have to just click on this plus symbol here and write whatever the code I want to. So let us say I want to see what is that x I have assigned and now I am going to simply execute by pressing shift and I return so it shows me the value that is assigned to the variable 2. And now if I want to see what is that is assigned to string 1 again I write string 1 here and write enter and you will see I see that the string 1 has this string hello word. But also Python gives us very easy way to accept inputs suppose like I want to instead of assigning value x directly here I want user to give a value here so I can for that I can use users through this function input. Let me execute this and let us see what happens so now see it is asking me to enter a number let me enter number 10 and then for the next step it is asking me to enter a string let us say engineering statistics and now I can press enter now these two outputs are shown. Notice that now I have another return I have basically converted this number x to a float and store it under num x. So basically if I want to store this numbers in a particular type then I will just use the type and then store them. And here also like because like users here just have taken input user even though I asked to enter a number if let us say user has entered some characters or maybe he just entered a number I want to store it under float so I use it and suppose when I asked him to enter a string so numbers are also some kind of string. So if users has entered a numbers as string instead of interpreting them as numbers I want to interpret the string that is what I use this function string and then store in this variable str1. So now let us see what I will get if I print this num x and string 1 so notice that since I have stored it as float it is taken stored the value I enter 10 as 10.0 and a string since I entered a proper string it has just stored it as a string. And now you can go back if you are just have a variable and you want to check what is its type you can use the function type here to get what kind of variable it is and for string you will see that string 1 you see that it is simply string 1. And here I can convert this number to string see that I use this function string on this number x now it is showing me under this inverted commas that means when it is coming as inverted commas this is clear that even though 10 is an integer but now it is treated as a string here. And now we can do this conversions between various types suppose if I have a number which is like a float or which has been given to 5.5 but I want to convert to integer I will just apply this function integer and then when I see what it is you will see that it is just shown as 5 ok. And to when we have to assign some variables we have to be careful and names to the variables we have to be careful we it is not that anything we can take as a variable name. For example, this I want to define a variable called this 10 dual curve but here 10 I have to replace by the integer 10 and I want to store in that variable value 56 if I do that it gives me error because this is not permitted I cannot use numbers and characters in defining a variable. Similarly, if I want to save this name Khuli under the variable class this is not accepted and Python will show me error because this class is a kind of a reserved variable ok. So we have to keep these things in mind like I cannot mix up numbers and characters in defining a variable and similarly I cannot use some reserved names for variables. Python allows us to do various operations and the good thing is like we can do additions and all in a very intuitive way without the syntax is so simple that we while writing they scored it is as if you are writing something on a paper. Like if you want to do this add two numbers a and b it is simply we have to write it as a plus b and if you have to subtract two numbers we have to simply write a minus b and if you have to multiply two numbers a and b it is simply a star b and if it is a division it is going to be written as a this backslash b and it is a division or with the floor that let where we ignore the fractional part then it is a two backslashes divided b and if you are only interested in the modulus then it is a percentage b and if you want to exponent a to b you have to use a this double star b and if you have to negate the number it is simply minus a. So here are some examples let us say I have this two values which I have stored in a and b here a is 34 and b is 3 like you see that like I can simply do the addition by doing this and I can print the value. So this is as simple as that. So notice that when I did a by b here that is the true division I got 11.33 like that but when I do a backslash b that is the I did a floor division I only get it as 11 the integer part was ignored. I hope these things are clear and also Python makes handling of the strings also pretty easy and very intuitive. Suppose I have two strings let us say one is two words hello and another one is word and I want to do concatenation of them it is like as if I am adding these two words or strings. So I can simply say a equals to c a plus b and when I print it you will just see that hello word. But when it did a plus b it just concatenated them back to back but if you want to add some space between the two words one option for that is like you add space by using this plus symbols here. So what it first did is like when I use this when I use this plus here it is adding space to a and after that it is adding b to that string. So that is what you will get the word which looks like this hello with a space and word. The multiplication is also pretty straightforward even if you want to use it on a strings. Suppose I have a string a b c then if I want to appear the strings three times all I need to do is take this a into 3 and if you want to add a space and then do multiply and add multiply and repeat them three times I have to add space this part will adding space and then repeat it three times. So this is how the output looks. Okay, so these are like a basic how to create variables and how to do some basic operations on numbers as well as strings. Now if you want to do now if you want to do coding maybe we have to do a lot of repeated task over numbers for that we need to check certain condition or do some looping operations. So let us look into the conditions how to check and some looping operations. First let us look into the if else conditions how it will work in Python. Suppose if you have a number n has a number and if I want to check whether this n is greater than 2 all I need to do is write it like this check whether n is greater than 2 and notice that after that I have this colon here and then I am going to check and write this like print the statement is correct and after that I do not need to write anything here. So the one important thing is after I write n is greater than 2 complete that with this colon and then print the statement but you have to properly index it align it. And for example if you after writing this you do this Python will automatically take where you should be writing the next condition here. Now let us write this now here since we have already put 18 in n this is true and that is why the statement is come out to be correct. And similarly if you want to check whether n is less than 2 I will do the same thing but now if you execute it say I am executing by compressing control sorry shift return but nothing is executed because the condition is failing. And now if you want to check we want to now check both like which of them is correct whether like the condition n is less than 2 holds or not we can first check where n equals to less than 2 put a colon there then print a statement the statement is correct if that is true else. So when I say else it is always going to be taken as a complement of this condition whatever the condition you have written for the if statement and again you have to end it by a colon and then print the statement is false ok. Now this could be expanded it is not that else cannot take any condition here else could also take a condition but in that case we have to write it as else if. So this is same thing we do in other language like c c plus plus. So if you want to check whether 2 numbers x and y let us say I want to check the condition x less than equals to y you check it and if that is true you want a statement like x is less than y and if x is greater than y that also you want to be stated and if none of these 2 holds then the only possibility is that both are equal and that you are going to write in the last case. Now we can also do so let me execute this now it is clear that since x is having value y phi and y is value 6 phi is less than 6 here is the correct value and now we can do the nesting of this under else conditions also we can put further if else for example if I want to check whether 2 numbers how they are first I can check whether they are equal if they are equal I am going to print x is equals to y else there are 2 possibilities either x can be greater than y so I write this and write the want to print it x greater than y else if x is not greater than y obviously it has to be less than y I am going to still print like this. So notice that the things is like this has to be properly this lines has to be properly indented you do not need to write like end every time like we do in you know c or c plus plus language here this end is automatically inferred by looking into the indentation. Now loops so we will stop here and we will continue discussion of loops in the next module.