Reputation: 1
I started writing the code for the file name alien_invasion.py in the book python crash course, page number 228. I encountered the following error- NameError: name 'name' is not defined
This occurs when the final lines of the program in the file alien_invasion.py written within the if block is executed. That is
if _name_ == '_main_':
ai. = AlienInvasion()
ai.run_game()
Upvotes: 0
Views: 199
Reputation: 43
You are missing '_' at the beginning and end. The code should look like this
if __name__ == '__main__':
# Make a game instance, and run the game.
ai = AlienInvasion()
ai.run_game()
Upvotes: 2