Python Forum
Mastermind/Guess the Code Game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mastermind/Guess the Code Game
#4
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Mastermind/Guess the Code Game - by JoeLamond - Oct-14-2018, 01:29 PM
RE: Mastermind/Guess the Code Game - by ichabod801 - Oct-14-2018, 04:31 PM
RE: Mastermind/Guess the Code Game - by JoeLamond - Oct-16-2018, 02:55 PM
RE: Mastermind/Guess the Code Game - by ichabod801 - Oct-16-2018, 07:18 PM
RE: Mastermind/Guess the Code Game - by ichabod801 - Oct-16-2018, 07:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess your number joe_momma 0 2,474 Oct-23-2020, 02:53 AM
Last Post: joe_momma
  Guess my number foksikrasa 0 2,421 May-28-2020, 04:12 PM
Last Post: foksikrasa
  guess my number GAME ronblue77 2 2,807 Nov-24-2019, 04:23 PM
Last Post: CodingStranger
  Guess the dice roll mini-game tawnnx 6 7,417 May-22-2018, 02:12 PM
Last Post: malonn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020