Oct-16-2018, 07:18 PM
The looping over indexes comes up so much we have a special tutorial for it. Sorry, I should have linked to that in my first post.
The if/main block is a common Python technique. Each module has a __name__ attribute. If the module is imported, it's the name of the file. If the module is executed as the top level module, __name__ is set to __main__. So the if/main block can be used to do something special when the module is not imported. Sometimes you might put test code in that section. Other times you would run a certain function if the module is executed at the top level, but not run it if the module is imported.
In this case, the if/main block may not be needed. If this is just a one-off game and you aren't going to use any of the code elsewhere, you don't really need one. But using code elsewhere is a good idea, and you may not realize until later that you want to do it. So encapsulating code into functions and making it easy to import them is a good habit to get into.
The if/main block is a common Python technique. Each module has a __name__ attribute. If the module is imported, it's the name of the file. If the module is executed as the top level module, __name__ is set to __main__. So the if/main block can be used to do something special when the module is not imported. Sometimes you might put test code in that section. Other times you would run a certain function if the module is executed at the top level, but not run it if the module is imported.
In this case, the if/main block may not be needed. If this is just a one-off game and you aren't going to use any of the code elsewhere, you don't really need one. But using code elsewhere is a good idea, and you may not realize until later that you want to do it. So encapsulating code into functions and making it easy to import them is a good habit to get into.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures