i'm a school teacher writing an addition app using Python. It was going ok but i didn't like the editor so i found a new one(NetBean6.5). i copied/pasted my code but the NBeans editor is looking for a "main" module... i've done a little c++ so i understand what it's looking for but i don't know where to put it or what it should look like. Below i the code i copied from the python.org editor.

can some one tell/show how/where to setup "main"?

for i in range(2):

addString = input('What addition table do you want to use ')
addTable = int(addString)
tryAgain ='Try again'
correct = 'CORRECT!'
import random
add1 = random.randrange(1,10,1)
print (addString +' + '+ str(add1)+ ' = ' )
stuAnswer= input()
stuInt= int(stuAnswer)
answer = (addTable+add1)

while answer !=stuInt:
print (tryAgain)
print(addString+' + '+str(add1)+' = ')
stuAnswer= input()
stuInt = int(stuAnswer)
answer = (addTable+add1)
else:

print (correct)


print (str(stuAnswer))
print( addTable+add1)

Recommended Answers

All 3 Replies

Please use code tags when posting code in this forum. If you don't, your code is excruciatingly hard to read and makes it less likely that forum members will answer your question.

To use code tags:
[code=python] # Put your code inside here

[/code]

Now regarding the 'main' module: there is no set way to do this in Python, as the language doesn't require you to use any specific structure; however the most common way that you'll see a 'main' function being represented is this:

import os

def main():
    """ This is the main function """
    pass

if __name__ == '__main__':
    main()

This convention is used most commonly to avoid certain code from running when importing from this module. Now, with that being said I'm not so convinced that an editor would force you to use that style (or any style for that matter). I think that your problem might be something entirely different.

Could you copy-paste the exact error that you're getting? Also, the subject of the thread mentions jython... Are you using jython or python?

i will surely use tags next time.

thank you for your reply.. i didn't get an error. i got a dialog box asking me to select main module.

thank you again,
frank

Actually Snee left this note somewhere:

I found a mildly more sensible solution to running simple Python files on NetBeans 6.5 -->

Create a new project, save it in a recognizable location and run it. Now you can create individual Python files and save them in the new project source subdirectory, for instance
C:\Python25\Beans\NewPythonProject\src

After that the 'Run File' option is activated, run and enjoy!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.