hello guys welcome to the fifth blog tutorial on Python programming for beginners and in this blog I'm going to show you how you can save your program or how you can save your Python program to use this program in the future so for example you want to save your Python program and run it whenever you need in future how you can do it I'm going to show you in this blog so till now we were using this Python shell and whatever code we write in this fight and shell it will execute this code very well but it's not able to save your program so whenever you just close the spider shell your program is gone it's and it's not saved anywhere so let's try to make a new file of new Python file so that we can use this Python file whenever we need and we don't even need to worry about closing this shell okay so how you can do this is you just need to open this Python shell you already know that you can just open this Python shell by going to your Python folder and just open idle Python GUI from here and this is that I didn't idle Python GUI which is a Python shell so just open it and just go to file here and just click new file and this will open a new file and you can save this file as Python file but first you need to write some code in here so I'm just giving you an example how you can make this Python file and how you can run it so for example we want to calculate the maximum of three values what you can do here is you can calculate the maximum of three values like this so I have already shown you how you can take the input like by using this input function and how you can convert this input to an integer by just typecasting this string value which you get from input to the integer and save it into variable so in the same way we have I have three valuable x y&z which are taking inputs from the user and what I'm going to do is
I'm just simply calculating the maximum value of these three number which you have user health and third and I'm going to print this maximum so maximum I'm calculating this from a function called max which I have shown you in the last blog that can take any number of argument right now I have only 3i argument because I want to compare three numbers and calculate the maximum value so let's try it to save this first so you just need to save this program in order to run it so you just need to go to file and just click save as and in here choose your path for the Python file and just give the name of your piping file for example test and make sure that this here save as type is python file here which is dot py file or dot py w file and save your file and now once your file is saved you can just run it just go to this one tab and you can just like this run module or f5 key okay so I'm going to run module and this will run my module like this so I'm going to give three numbers for example 22 second number 33 third number 44 and it gives me the answer that maximum of these three values is 44 right I can do this in a better way that I can print something first that the result is or the max of three three values is and it depends upon you how you can run this is just an example okay so how do you want me your program you are free to make it and this is just an example how you can save your file but still it doesn't solve our purpose because it's running our code in the shell and we cannot you know always run our program and you cannot open our Python shell everywhere you know you want to run your Python file as an executable file right you don't don't need to you know open this Python shell every time you need to run your Python program and how you can run your program directly is you just need to go to the folder wherever you have saved your Python file so I have saved my file in files here but there is a little correction you need to make in this program and what is the correction because it's taking three inputs and it will take three inputs and it's going to print this answer and just after you know giving you the answer or printing the answer it will instantly exit so what you need to do just need to give something so that it can stay so just write in put and in put in here you can just give string that please press ENTER to exit and this will you know keep your screen on and until and unless you press ENTER it will not exit just save your program once again just go to file and save it and then go to the python file wherever you have saved your python file okay just go to the python file you can right-click and you can open if you go into if you are going to open it it will open it in the Python terminal and this will run your program directly you don't even need to use this Python shell or what you can do you can just directly double click it and it will open your Python program and it will give you the option please enter first number I will enter first number 11 second number 43 third number 43 and when I press ENTER it will give me the answer which is 43 the max of Treena values is 43 and now it will give me this option that press ENTER to exit and when I press ENTER or any other key I will exit from my Python code okay so once again you can save your python file by going to this file tab and make a new file and just save your file once you have done writing your code you just need to save your file as a py files you just need to go to file and save as and you just need to give a name to your file and make sure that it's a Python file type ok once your file is ready you just need to or once your food is ready you just need to save it and once you have saved your file you just need to go to the file and run it if you have remembered I have shown you in the first blog or that Python doesn't compile your program button directly runs your program so you don't need to compile your program with it to win run your program directly ok and if any error occurs in your program it will give you the answer at the runtime but I'm not at the compiled time so this is why you can run your Python file directly like this by double clicking ok so I hope you have enjoyed this blog
Post a Comment