First of all let me thank you and Geoframer for your patience;it was very
kind that you bothered answering this,as I realize this is very basic
stuff.You people are Smart and Caring Dudes,which is a powerful combo for
educators!!

"Out of curiosity, what materials are you using to learn how to program?"

Well, mostly Google! I have just finished that RUR-PLE tutorial by Andre
Roberge, read some of the Python documentation-not as focused as I should,I
admit;many programming concepts are simply  totally alien to me,so I also
use Wikipedia a lot.They have a Python tutorial.Sometimes I do some math
research, as I only know very basic math,predicate logic and
statistics.Ialso tried a pygame tutorial,but can't import the damn
module without at
least one error and can't get the damn chimp.bmp file loaded!!!I used
os.path.join("folder","file") to no success...
Thank you again,and once more in advance - if you would be so kind as to
point me learning material...My spare time is very short,between graduation
and work,so I would appreciate very didatic material...Thank you guys again!


2007/1/19, Danny Yoo <[EMAIL PROTECTED]>:


> I've been dabbling into Python for about 6 weeks now.I'm a Social
> Sciences student who just got interested in programming and chose Python
> as first language.

Out of curiosity, what materials are you using to learn how to program?



> Isn't it legal to start a new block of code when starting a
> definition?And how come it returns 'variable' not defined,when they are
> defined by the = ??Should i make them global?

Wait, wait.  I think you may be misunderstanding the use of 'global'.
You should not be using global unless you really need it.



I see three variables here that you are interested in:

    altura_aeronave
    largura_aeronave
    comprimento

Are these always collected together?  If they are related, you should have
a single structure that holds them together, rather than represent them as
three separate variables.


Concretely, you can represent these three values as a single tuple.  You
can think of it as a "vector" from your mathematics class.  For example:

#################################################
def make_measure(start, stop):
    """make_measure: number number -> measure
    Creates a new measure from start and stop."""
    return (start, stop)

def measure_start(a_measure):
    """measure_start: measure -> number
    Selects the start portion of a measure."""
    return a_measure[0]

def measure_stop(a_measure):
    """measure_end: measure -> end
    Selects the stop portion of a measure."""
    return a_measure[1]
#################################################


That is, these functions take inputs and produce outputs.  That should be
a concept that you are familiar with from your previous experience:

    f(x) = 2x     (math notation)

is a function that takes a number and produces the double of that number.
We write this in Python as:

################
def double(x):
    """double: number -> number
    Returns the double of x."""
    return x * 2
################


Getting back to the measure example: once we have these functions to build
measures and take them apart, we can then use these like this:

################################################
## Small test program
m1 = make_measure(3, 4)
m2 = make_measure(17, 42)
print "m1", measure_start(m1), measure_stop(m1)
print "m2", measure_start(m2), measure_stop(m2)
################################################

If we dislike the duplication of those last two statements here, we can
create a function that doesn't produce an output, but it still takes
input:


########################################################################
def print_measure(header_name, a_measure):
    """print_measure: measure string -> None
    Prints out the measurement.
    """
    print header_name, measure_start(a_measure), measure_stop(a_measure)
########################################################################


After we define this helper function "print_measure()", our little program
can now look like this:

#########################
## Small test program
m1 = make_measure(3, 4)
m2 = make_measure(17, 42)
print_measure("m1", m1)
print_measure("m2", m2)
#########################

Notice that, here, we do not need to say anything about "globals" to make
effective programs.  We are simply passing values back and forth as
parameters.


Does this make sense so far?  If you have any questions, please feel free
to ask.  Please continue to reply to Tutor by using your email client's
Reply to All feature.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to