decision structures so farmost of our programs have had line at the bottom to invoke the main function main(as you knowthis is what actually starts program running these programs are suitable for running directly in windowing environmentyou might run file by (double-)clicking its icon or you might type command like python py since python evaluates the lines of module during the import processour current programs also run when they are imported into either an interactive python session or into another python program generallyit is nicer not to have modules run as they are imported when testing program interactivelythe usual approach is to first import the module and then call its main (or some other functioneach time we want to run it in program designed to be either imported (without runningor run directlythe call to main at the bottom must be made conditional simple decision should do the trick if main(we just need to figure out suitable condition whenever module is importedpython sets special variable in the module called __name__ to be the name of the imported module here is an example interaction showing what happens with the math libraryimport math math __name__ 'mathyou can see thatwhen importedthe __name__ variable inside the math module is assigned the string 'mathhoweverwhen python code is being run directly (not imported)python sets the value of __name__ to be '__main__to see this in actionyou just need to start python shell and look at the value __name__ '__main__soif module is importedthe code in that module will see variable called __name__ whose value is the name of the module when file is run directlythe code will see that __name__ has the value '__main__a module can determine how it is being used by inspecting this variable putting the pieces togetherwe can change the final lines of our programs to look like thisif __name__ ='__main__'main(this guarantees that main will automatically run when the program is invoked directlybut it will not run if the module is imported you will see line of code similar to this at the bottom of virtually every python program