different errors, return outside function and others
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Feb 23 04:57:18 EST 2009
En Mon, 23 Feb 2009 07:07:57 -0200, Tony <sternbrightblade at gmail.com>
escribió:
> ok thank you for that input, this is my first class in programming and
> its
> the only one the school offers. im pretty sure those are supposed to be
> modules
> that im writting. would it make a difference if those were modules and
> not
> functions? kinda stupid question there but im trying to learn as much as
> possible.
Each module is a separate file, with extension .py
If you put all your code in a single file, you write a single module.
That's fine in this case, unless it grows to something unmanageable.
Functions are blocks of code that have a name and "do" something specific,
and usually return some result. They start with the keyword "def". You
have defined several functions already, but called them "modules" in the
comments, that's wrong and may be confusing.
> Also anything with def infront of it example def start(): would be a
> function correct? also im Using 2.5 and the IDLE to do this
Exactly!
I think you have written so much code without testing it. It's time to
test every piece now. Start with... the start function, obviously!
But before, you have to clean your code. There are a few strange lines
that should not be there (all those lines on the left margin that aren't
"def" statements, like intro_area(), alley()...). Just remove or comment
them.
Then you can start testing each function, one at a time. Simply call the
function with the desired parameters (if any), right at the bottom of the
file. To test the first one (start), use something like this:
print "about to call start()"
result = start()
print "start() finished, result=", result
and do the same for each individual function. Once you know each piece
works fine, you can start combining them until you build the complete
program.
--
Gabriel Genellina
More information about the Python-list
mailing list