'elp!!!!!!!1Totally Clueless Newbie In Distress

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

'elp!!!!!!!1Totally Clueless Newbie In Distress

Karl Wittgenstein
Dear Smart Caring Dude,
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.I have little time to practice and I am just getting into  programming concepts,so please be patient,in case you are so kind as to enlighten this poor soul.
I am trying to write this program which should compare values that are set by the program  through user's choice to values that the user enters on a prompt.I use SPE on windows xp,and it tells me that there are indentation erros on the definitions.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?
I would be very grateful to the patient soul that answers these questions,as my learning interest is sincere and the knowledge sources so disperse.
Here goes the code:
 
#Ok,this is supposed to be a 2 option choice between values 1 and 4,
#i want the value to determine the variable values inside the function
def porao():
    porao = raw_input()
    if porao == 1 :
        global altura_aeronave = 111
        global largura_aeronave = 112
        global comprimento = 211
    elif porao == 4:
       global altura_aeronave = 112
       global largura_aeronave = 113
       global comprimento = 212
    else:
        print "Porão inexistente"
#These three functions were supposed to get input from user so it can be compared
#with the values determinated(determined?)above
def largura():
   global largura=input()
def altura():
   global altura=input()
def comprimento():
   global comprimento = input()
#These are the comparison functions
def largura_compativel ():
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
def altura_compativel ():
    if not altura <= altura_aeronave:
        print 'Volume alto demais!'
def comprimento_compativel ():
    if not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
#Try to run this damn thing,man!!!!!1
porao()
largura()
altura()
comprimento()
largura_compativel()
altura_compativel
comprimento_compativel()
 

_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Geoframer
Alright this code is actually littered with bugs, but don't feel bad, because as you state you are new to the whole programming thing. I'll try to explain the things i see going wrong (please take into account that i'm also a new pythonist ;-))

***
You get the error 'variable undefined' because you are declaring a global in an incorrect manner. The correct manner is to define the variable in the global scope then start a definition, declare that you are using a global variable and then assign it. Like this :

bla = 'Hello world'

def func():
    global bla
    print bla
***
If you do :
porao = raw_input()
You'll define the integer value as a string, not an integer. If you are sure that only an integer will be entered use input() (slower) or int(raw_input()). In either case you should use try and except clauses more in your code because if not a 1 or 4 is entered your code will continue without having the variables declared! Leading to other errors.
***
Now suppose you get the definitions using globals correct then you'll get new errors stating that an 'int' is not callable.
This happens because you define for example altura as an integer and then also define a function called altura. If you now use :
altura()
It'll try to call the integer object and will fail.
Easy solution would be to make the function something like alturadef()
***
As for your identation you should use consistent identation... I suggest using python -t or python -tt to compile your script and it will give warnings/errors where the identation goes wrong.
***
Here's how i altered your code (quick and dirty probably, it should be more clean using try and except clauses and what not) to get it to work but you can probably better look that up in a python book and then return to the list if you don't understand it :

#Ok,this is supposed to be a 2 option choice between values 1 and 4,
#i want the value to determine the variable values inside the function

altura_aeronave = 0
largura_aeronave = 0
comprimento_aeronave = 0
comprimento = 0
largura = 0
altura = 0

def porao():
    global altura_aeronave, largura_aeronave, comprimento
    porao = input()
    if porao == 1 :
        altura_aeronave = 111
        largura_aeronave = 112
        comprimento = 211
    elif porao == 4:
        altura_aeronave = 112
        largura_aeronave = 113
        comprimento = 212
    else:
        print "Porão inexistente"
       
#These three functions were supposed to get input from user so it can be compared
#with the values determinated(determined?)above
def larguradef():
    global largura
    largura=input()

def alturadef():
    global altura
    altura=input()

def comprimentodef():
    global comprimento
    comprimento = input()
   
#These are the comparison functions
def largura_compativel ():
    global largura, largura_aeronave
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
       
def altura_compativel ():
    global altura, altura_aeronave
    if not altura <= altura_aeronave:
        print 'Volume alto demais!'
       
def comprimento_compativel ():
    global comprimento, comprimento_aeronave
    if not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
       
#Try to run this damn thing,man!!!!!1
porao()
#print altura_aeronave, largura_aeronave, comprimento
larguradef()
alturadef()
comprimentodef()
largura_compativel()
altura_compativel
comprimento_compativel()








On 1/19/07, Karl Wittgenstein <[hidden email] > wrote:
Dear Smart Caring Dude,
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.I have little time to practice and I am just getting into  programming concepts,so please be patient,in case you are so kind as to enlighten this poor soul.
I am trying to write this program which should compare values that are set by the program  through user's choice to values that the user enters on a prompt.I use SPE on windows xp,and it tells me that there are indentation erros on the definitions.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?
I would be very grateful to the patient soul that answers these questions,as my learning interest is sincere and the knowledge sources so disperse.
Here goes the code:
 
#Ok,this is supposed to be a 2 option choice between values 1 and 4,
#i want the value to determine the variable values inside the function
def porao():
    porao = raw_input()
    if porao == 1 :
        global altura_aeronave = 111
        global largura_aeronave = 112
        global comprimento = 211
    elif porao == 4:
       global altura_aeronave = 112
       global largura_aeronave = 113
       global comprimento = 212
    else:
        print "Porão inexistente"
#These three functions were supposed to get input from user so it can be compared
#with the values determinated(determined?)above
def largura():
   global largura=input()
def altura():
   global altura=input()
def comprimento():
   global comprimento = input()
#These are the comparison functions
def largura_compativel ():
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
def altura_compativel ():
    if not altura <= altura_aeronave:
        print 'Volume alto demais!'
def comprimento_compativel ():
    if not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
#Try to run this damn thing,man!!!!!1
porao()
largura()
altura()
comprimento()
largura_compativel()
altura_compativel
comprimento_compativel()
 

_______________________________________________
Tutor maillist  -  [hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/tutor" target="_blank"> http://mail.python.org/mailman/listinfo/tutor




_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Geoframer
Accidentally the number of function definitions does not help the clarity of the program, even though it's completely unclear to me what exactly you are trying to do. :-)
I rewrote your program a bit combining the definition of the functions, the comparision of the functions and removed the chance that your program goes on the define/compare values that have not been defined.

*** Insert redone code ***
altura_aeronave = 0
largura_aeronave = 0
comprimento_aeronave = 0
comprimento = 0
largura = 0
altura = 0

def compativel():
    global altura, altura_aeronave, comprimento, comprimento_aeronave, \
           largura, largura_aeronave
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
    elif not altura <= altura_aeronave:
        print 'Volume alto demais!'
    elif not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
       
def define():
    global largura, altura, comprimento
    largura=input()
    altura=input()
    comprimento=input()
   
def porao():
    global altura_aeronave, largura_aeronave, comprimento
    porao = input()
    if porao == 1 :
        altura_aeronave = 111
        largura_aeronave = 112
        comprimento = 211
        return 1
    elif porao == 4:
        altura_aeronave = 112
        largura_aeronave = 113
        comprimento = 212
        return 1
    else:
        print "Porao inexistente!"


if porao():
    define()
    compativel()

On 1/19/07, Geoframer <[hidden email]> wrote:
Alright this code is actually littered with bugs, but don't feel bad, because as you state you are new to the whole programming thing. I'll try to explain the things i see going wrong (please take into account that i'm also a new pythonist ;-))

***
You get the error 'variable undefined' because you are declaring a global in an incorrect manner. The correct manner is to define the variable in the global scope then start a definition, declare that you are using a global variable and then assign it. Like this :

bla = 'Hello world'

def func():
    global bla
    print bla
***
If you do :
porao = raw_input()
You'll define the integer value as a string, not an integer. If you are sure that only an integer will be entered use input() (slower) or int(raw_input()). In either case you should use try and except clauses more in your code because if not a 1 or 4 is entered your code will continue without having the variables declared! Leading to other errors.
***
Now suppose you get the definitions using globals correct then you'll get new errors stating that an 'int' is not callable.
This happens because you define for example altura as an integer and then also define a function called altura. If you now use :
altura()
It'll try to call the integer object and will fail.
Easy solution would be to make the function something like alturadef()
***
As for your identation you should use consistent identation... I suggest using python -t or python -tt to compile your script and it will give warnings/errors where the identation goes wrong.
***
Here's how i altered your code (quick and dirty probably, it should be more clean using try and except clauses and what not) to get it to work but you can probably better look that up in a python book and then return to the list if you don't understand it :

#Ok,this is supposed to be a 2 option choice between values 1 and 4,
#i want the value to determine the variable values inside the function

altura_aeronave = 0
largura_aeronave = 0
comprimento_aeronave = 0
comprimento = 0
largura = 0
altura = 0

def porao():
    global altura_aeronave, largura_aeronave, comprimento
    porao = input()
    if porao == 1 :
        altura_aeronave = 111
        largura_aeronave = 112
        comprimento = 211
    elif porao == 4:
        altura_aeronave = 112
        largura_aeronave = 113
        comprimento = 212
    else:
        print "Porão inexistente"
       
#These three functions were supposed to get input from user so it can be compared
#with the values determinated(determined?)above
def larguradef():
    global largura
    largura=input()

def alturadef():
    global altura
    altura=input()

def comprimentodef():
    global comprimento
    comprimento = input()
   
#These are the comparison functions
def largura_compativel ():
    global largura, largura_aeronave
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
       
def altura_compativel ():
    global altura, altura_aeronave
    if not altura <= altura_aeronave:
        print 'Volume alto demais!'
       
def comprimento_compativel ():
    global comprimento, comprimento_aeronave
    if not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
       
#Try to run this damn thing,man!!!!!1
porao()
#print altura_aeronave, largura_aeronave, comprimento
larguradef()
alturadef()
comprimentodef()
largura_compativel()
altura_compativel
comprimento_compativel()








On 1/19/07, Karl Wittgenstein <[hidden email] > wrote:
Dear Smart Caring Dude,
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.I have little time to practice and I am just getting into  programming concepts,so please be patient,in case you are so kind as to enlighten this poor soul.
I am trying to write this program which should compare values that are set by the program  through user's choice to values that the user enters on a prompt.I use SPE on windows xp,and it tells me that there are indentation erros on the definitions.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?
I would be very grateful to the patient soul that answers these questions,as my learning interest is sincere and the knowledge sources so disperse.
Here goes the code:
 
#Ok,this is supposed to be a 2 option choice between values 1 and 4,
#i want the value to determine the variable values inside the function
def porao():
    porao = raw_input()
    if porao == 1 :
        global altura_aeronave = 111
        global largura_aeronave = 112
        global comprimento = 211
    elif porao == 4:
       global altura_aeronave = 112
       global largura_aeronave = 113
       global comprimento = 212
    else:
        print "Porão inexistente"
#These three functions were supposed to get input from user so it can be compared
#with the values determinated(determined?)above
def largura():
   global largura=input()
def altura():
   global altura=input()
def comprimento():
   global comprimento = input()
#These are the comparison functions
def largura_compativel ():
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
def altura_compativel ():
    if not altura <= altura_aeronave:
        print 'Volume alto demais!'
def comprimento_compativel ():
    if not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
#Try to run this damn thing,man!!!!!1
porao()
largura()
altura()
comprimento()
largura_compativel()
altura_compativel
comprimento_compativel()
 

_______________________________________________
Tutor maillist  -  [hidden email]
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://mail.python.org/mailman/listinfo/tutor





_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Geoframer
As i stated i'm somewhat new to python myself so i defined the variables  in a somewhat old fashion manner. The correct code is below. I also added some comments because i think you defined the wrong variable somewhere also...
Because your code led to comprimento being compared to comprimento_aeronave which was never defined anywhere, so i took it you ment comprimento_aeronave there....

This code below is fully functional without any errors (not even identation warnings ;-) ). So if this doesn't work at your computer something else is possible wrong. Incidentally if you hit the following sequence : 1 2 3 4. The program just terminates without a message... You'd have to insert what's happening in such a case yourself.

**** insert code ****
global altura_aeronave, largura_aeronave, comprimento_aeronave, comprimento, \
       largura, altura

def compativel():
    global altura, altura_aeronave, comprimento, comprimento_aeronave, \
           largura, largura_aeronave
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
    elif not altura <= altura_aeronave:
        print 'Volume alto demais!'
    elif not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
       
def define():
    global largura, altura, comprimento
    largura=input()
    altura=input()
    comprimento=input()
   
def porao():
    global altura_aeronave, largura_aeronave, comprimento_aeronave
    porao = input()
    if porao == 1 :
        altura_aeronave = 111
        largura_aeronave = 112
        comprimento_aeronave = 211 #You originally had comprimento here?
        return 1
    elif porao == 4:
        altura_aeronave = 112
        largura_aeronave = 113
        comprimento_aeronave = 212 #Same here
        return 1
    else:
        print "Porao inexistente!"


if porao():
    define()
    compativel()

*** end inserted code ***

HTH - Geoframer

On 1/19/07, Geoframer <[hidden email]> wrote:
Accidentally the number of function definitions does not help the clarity of the program, even though it's completely unclear to me what exactly you are trying to do. :-)
I rewrote your program a bit combining the definition of the functions, the comparision of the functions and removed the chance that your program goes on the define/compare values that have not been defined.

*** Insert redone code ***
altura_aeronave = 0
largura_aeronave = 0
comprimento_aeronave = 0
comprimento = 0
largura = 0
altura = 0

def compativel():
    global altura, altura_aeronave, comprimento, comprimento_aeronave, \
           largura, largura_aeronave
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
    elif not altura <= altura_aeronave:
        print 'Volume alto demais!'
    elif not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
       
def define():
    global largura, altura, comprimento
    largura=input()
    altura=input()
    comprimento=input()
   
def porao():
    global altura_aeronave, largura_aeronave, comprimento
    porao = input()
    if porao == 1 :
        altura_aeronave = 111
        largura_aeronave = 112
        comprimento = 211
        return 1
    elif porao == 4:
        altura_aeronave = 112
        largura_aeronave = 113
        comprimento = 212
        return 1
    else:
        print "Porao inexistente!"


if porao():
    define()
    compativel()


On 1/19/07, Geoframer <[hidden email]> wrote:
Alright this code is actually littered with bugs, but don't feel bad, because as you state you are new to the whole programming thing. I'll try to explain the things i see going wrong (please take into account that i'm also a new pythonist ;-))

***
You get the error 'variable undefined' because you are declaring a global in an incorrect manner. The correct manner is to define the variable in the global scope then start a definition, declare that you are using a global variable and then assign it. Like this :

bla = 'Hello world'

def func():
    global bla
    print bla
***
If you do :
porao = raw_input()
You'll define the integer value as a string, not an integer. If you are sure that only an integer will be entered use input() (slower) or int(raw_input()). In either case you should use try and except clauses more in your code because if not a 1 or 4 is entered your code will continue without having the variables declared! Leading to other errors.
***
Now suppose you get the definitions using globals correct then you'll get new errors stating that an 'int' is not callable.
This happens because you define for example altura as an integer and then also define a function called altura. If you now use :
altura()
It'll try to call the integer object and will fail.
Easy solution would be to make the function something like alturadef()
***
As for your identation you should use consistent identation... I suggest using python -t or python -tt to compile your script and it will give warnings/errors where the identation goes wrong.
***
Here's how i altered your code (quick and dirty probably, it should be more clean using try and except clauses and what not) to get it to work but you can probably better look that up in a python book and then return to the list if you don't understand it :

#Ok,this is supposed to be a 2 option choice between values 1 and 4,
#i want the value to determine the variable values inside the function

altura_aeronave = 0
largura_aeronave = 0
comprimento_aeronave = 0
comprimento = 0
largura = 0
altura = 0

def porao():
    global altura_aeronave, largura_aeronave, comprimento
    porao = input()
    if porao == 1 :
        altura_aeronave = 111
        largura_aeronave = 112
        comprimento = 211
    elif porao == 4:
        altura_aeronave = 112
        largura_aeronave = 113
        comprimento = 212
    else:
        print "Porão inexistente"
       
#These three functions were supposed to get input from user so it can be compared
#with the values determinated(determined?)above
def larguradef():
    global largura
    largura=input()

def alturadef():
    global altura
    altura=input()

def comprimentodef():
    global comprimento
    comprimento = input()
   
#These are the comparison functions
def largura_compativel ():
    global largura, largura_aeronave
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
       
def altura_compativel ():
    global altura, altura_aeronave
    if not altura <= altura_aeronave:
        print 'Volume alto demais!'
       
def comprimento_compativel ():
    global comprimento, comprimento_aeronave
    if not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
       
#Try to run this damn thing,man!!!!!1
porao()
#print altura_aeronave, largura_aeronave, comprimento
larguradef()
alturadef()
comprimentodef()
largura_compativel()
altura_compativel
comprimento_compativel()








On 1/19/07, Karl Wittgenstein <[hidden email] > wrote:
Dear Smart Caring Dude,
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.I have little time to practice and I am just getting into  programming concepts,so please be patient,in case you are so kind as to enlighten this poor soul.
I am trying to write this program which should compare values that are set by the program  through user's choice to values that the user enters on a prompt.I use SPE on windows xp,and it tells me that there are indentation erros on the definitions.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?
I would be very grateful to the patient soul that answers these questions,as my learning interest is sincere and the knowledge sources so disperse.
Here goes the code:
 
#Ok,this is supposed to be a 2 option choice between values 1 and 4,
#i want the value to determine the variable values inside the function
def porao():
    porao = raw_input()
    if porao == 1 :
        global altura_aeronave = 111
        global largura_aeronave = 112
        global comprimento = 211
    elif porao == 4:
       global altura_aeronave = 112
       global largura_aeronave = 113
       global comprimento = 212
    else:
        print "Porão inexistente"
#These three functions were supposed to get input from user so it can be compared
#with the values determinated(determined?)above
def largura():
   global largura=input()
def altura():
   global altura=input()
def comprimento():
   global comprimento = input()
#These are the comparison functions
def largura_compativel ():
    if not largura <= largura_aeronave:
        print 'Volume largo demais!'
def altura_compativel ():
    if not altura <= altura_aeronave:
        print 'Volume alto demais!'
def comprimento_compativel ():
    if not comprimento<=comprimento_aeronave:
        print 'Volume comprido demais!'
#Try to run this damn thing,man!!!!!1
porao()
largura()
altura()
comprimento()
largura_compativel()
altura_compativel
comprimento_compativel()
 

_______________________________________________
Tutor maillist  -  [hidden email]
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://mail.python.org/mailman/listinfo/tutor






_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Danny Yoo
In reply to this post by Karl Wittgenstein

> 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  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Karl Wittgenstein
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.I also 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 <[hidden email]>:

> 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  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Karl Wittgenstein
I would also like to ask what skills you think I should develop so I can approach programming more            
' natively', and would like to clarify the following issue:
input("Something") usually displays Something when prompting for input;why is that the case when I run a single line of code and isn't when I use many?When I run three lines straight in this format,only the first message and prompt are displayed...That is surely out of the scope of my current knowledge....Which is not very encompassing,anyway.

 
2007/1/20, Karl Wittgenstein <[hidden email]>:
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.I also 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 <[hidden email]>:

> 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  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Kent Johnson
In reply to this post by Karl Wittgenstein
Karl Wittgenstein wrote:
> 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!

Try one of the tutorials listed here
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

or one of these books:
http://effbot.org/pyfaq/tutor-what-are-some-good-books-on-python.htm

Kent


_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Kent Johnson
In reply to this post by Karl Wittgenstein
Karl Wittgenstein wrote:
> I would also like to ask what skills you think I should develop so I can
> approach programming more            
> ' natively', and would like to clarify the following issue:
> input("Something") usually displays Something when prompting for
> input;why is that the case when I run a single line of code and isn't
> when I use many?When I run three lines straight in this format,only the
> first message and prompt are displayed...That is surely out of the scope
> of my current knowledge....Which is not very encompassing,anyway.

input('Something') displays the prompt 'Something' and then waits for
input up to a new line. When you enter the input it will execute the
next statement which may be another input().

Kent

_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Karl Wittgenstein
"input('Something') displays the prompt 'Something' and then waits for
input up to a new line. When you enter the input it will execute the
next statement which may be another input()."
It should be so,man,I believe you.But believe me when I say that THIS DAMN INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive caps,it's just frustration biting my ancles...Maybe it's a SPE problem??
Thank you.


 
2007/1/20, Kent Johnson <[hidden email]>:
Karl Wittgenstein wrote:
> I would also like to ask what skills you think I should develop so I can
> approach programming more
> ' natively', and would like to clarify the following issue:
> input("Something") usually displays Something when prompting for
> input;why is that the case when I run a single line of code and isn't
> when I use many?When I run three lines straight in this format,only the
> first message and prompt are displayed...That is surely out of the scope
> of my current knowledge....Which is not very encompassing,anyway.

input('Something') displays the prompt 'Something' and then waits for
input up to a new line. When you enter the input it will execute the
next statement which may be another input().

Kent



_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Kent Johnson
Karl Wittgenstein wrote:
> "input('Something') displays the prompt 'Something' and then waits for
> input up to a new line. When you enter the input it will execute the
> next statement which may be another input()."
> It should be so,man,I believe you.But believe me when I say that THIS
> DAMN INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive
> caps,it's just frustration biting my ancles...Maybe it's a SPE problem??
> Thank you.

Can you describe exactly what you are doing? And please stop with the
swear words, they are not appropriate to this list.

Kent

_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Karl Wittgenstein
Ok,got the script working almost fine now...The only problem is that the program window closes before we can get a glimpse of the answer...I use SPE under WinXP, and have seen this problem in every script i try...This is the script,as redone by a Smart Caring Dude on this list:

global altura_aeronave, largura_aeronave, comprimento_aeronave, comprimento,largura, altura

def compativel():
   global altura, altura_aeronave, comprimento, comprimento_aeronave, \
          largura, largura_aeronave
   if not largura <= largura_aeronave:
       print 'Volume largo demais!'
   elif not altura <= altura_aeronave:
       print 'Volume alto demais!'
   elif not comprimento<=comprimento_aeronave:
       print 'Volume comprido demais!'
def define():
   global largura, altura, comprimento
   largura=input("Por favor informe a largura do volume em cm")
   altura=input("Por favor informe a altura do volume em cm")
   comprimento=input("Por favor informe o comprimento do volume em cm")

def porao():
   global altura_aeronave, largura_aeronave, comprimento_aeronave
   porao = input("Por favor informe o porão a ser utilizado:1-4")
   if porao == 1 :
       altura_aeronave = 111
       largura_aeronave = 112
       comprimento_aeronave = 211 #You originally had comprimento here?
       return 1
   elif porao == 4:
       altura_aeronave = 112
       largura_aeronave = 113
       comprimento_aeronave = 212 #Same here
       return 1
   else:
       print "Porao inexistente!"

if porao():
   define()
   compativel()



2007/1/20, Kent Johnson <[hidden email]>:
Karl Wittgenstein wrote:
> "input('Something') displays the prompt 'Something' and then waits for
> input up to a new line. When you enter the input it will execute the
> next statement which may be another input()."
> It should be so,man,I believe you.But believe me when I say that THIS
> DAMN INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive
> caps,it's just frustration biting my ancles...Maybe it's a SPE problem??
> Thank you.

Can you describe exactly what you are doing? And please stop with the
swear words, they are not appropriate to this list.

Kent



_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Karl Wittgenstein
In reply to this post by Kent Johnson
Sorry for the swear words...

2007/1/20, Kent Johnson <[hidden email]>:
Karl Wittgenstein wrote:
> "input('Something') displays the prompt 'Something' and then waits for
> input up to a new line. When you enter the input it will execute the
> next statement which may be another input()."
> It should be so,man,I believe you.But believe me when I say that THIS
> DAMN INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive
> caps,it's just frustration biting my ancles...Maybe it's a SPE problem??
> Thank you.

Can you describe exactly what you are doing? And please stop with the
swear words, they are not appropriate to this list.

Kent



_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

David Rock
In reply to this post by Karl Wittgenstein
* Karl Wittgenstein <[hidden email]> [2007-01-20 13:10]:
> Ok,got the script working almost fine now...The only problem is that the
> program window closes before we can get a glimpse of the answer...I use SPE
> under WinXP, and have seen this problem in every script i try...This is the
> script,as redone by a Smart Caring Dude on this list:

It sounds like you need to run it from a command window.  Running it the
way you are isn't meant to leave a window up after the script is
finished. Do Start->Run->cmd  on XP to get a command window.  python
should already be in your path, so typing "python" at the propmt should
result in it running the interpreter.  If that works, exit the
interpreter and type "python scriptname" That should run your script,
and you will see the results in the command window because it won't
close after the script is done.

--
David Rock
[hidden email]
_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Roel Schroeven
In reply to this post by Karl Wittgenstein
Karl Wittgenstein schreef:
> Ok,got the script working almost fine now...The only problem is that the
> program window closes before we can get a glimpse of the answer...I use
> SPE under WinXP, and have seen this problem in every script i try...

Any program running in a console window does that. There are two ways
around:
- open a console window and run your program from there, as David Rock
describes
- you can work around it by adding raw_input("Press enter") as the very
last line of the script

--
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

janos.juhasz
In reply to this post by Karl Wittgenstein
Dear Karl,


I use getch() when I start my script from the windows desktop and
I am interested about its output.

import msvcrt
raw_input('Are you distressed ?\n')
print ('It will be better, I am sure :)')
msvcrt.getch() # append as last line

> Subject: Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress
> To: [hidden email]
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=us-ascii

> * Karl Wittgenstein <[hidden email]> [2007-01-20 13:10]:
> > Ok,got the script working almost fine now...The only problem is that
the
> > program window closes before we can get a glimpse of the answer...I
use SPE
> > under WinXP, and have seen this problem in every script i try...This
is the
> > script,as redone by a Smart Caring Dude on this list:


Yours sincerely,
______________________________
János Juhász

_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Luke Paireepinart
János Juhász wrote:

> Dear Karl,
>
>
> I use getch() when I start my script from the windows desktop and
> I am interested about its output.
>
> import msvcrt
> raw_input('Are you distressed ?\n')
> print ('It will be better, I am sure :)')
> msvcrt.getch() # append as last line
And where is the interesting output?  What were you expecting, and what
did you get?
_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

jim stockford
In reply to this post by Karl Wittgenstein

    no need for apology on my side. there's
    no agreed-upon and expressed policy.
    i like the model that we accept each
other as we are.

On Jan 20, 2007, at 7:10 AM, Karl Wittgenstein wrote:

> Sorry for the swear words...
>
> 2007/1/20, Kent Johnson <[hidden email]>: Karl Wittgenstein wrote:
>> > "input('Something') displays the prompt 'Something' and then waits
>> for
>> > input up to a new line. When you enter the input it will execute the
>> > next statement which may be another input()."
>> > It should be so,man,I believe you.But believe me when I say that
>> THIS
>> > DAMN INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive
>> > caps,it's just frustration biting my ancles...Maybe it's a SPE
>> problem??
>> > Thank you.
>>
>> Can you describe exactly what you are doing? And please stop with the
>> swear words, they are not appropriate to this list.
>>
>> Kent
>>
> _______________________________________________
> Tutor maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: 'elp!!!!!!!1Totally Clueless Newbie In Distress

Danny Yoo


On Sun, 21 Jan 2007, jim stockford wrote:

>    no need for apology on my side. there's
>    no agreed-upon and expressed policy.
>    i like the model that we accept each
> other as we are.

[meta; not really related to Python programming]

Hi Jim,

I did want to bring up that there are some community-held expectations on
what to write on the list.  They're certainly not set in stone, but it's
helpful to know about them.  Here's one description of an otherwise
unspoken expectation:

    http://www.catb.org/~esr/faqs/smart-questions.html#writewell


Generally, when we see someone being too frustrated by a problem to
describe it properly to the rest of us, that's something that should be
brought up to the poster, so that they can improve their writing on the
Tutor list.

When we do so, we're not trying to coerse the poster to change who they
are personally, because that would be domination.  But we are trying to
say that if they are primarily focused on describing their frustration
rather than the problem itself, they stand a good chance at succeeding.
That is, they can risk frustrating the people who they are asking for
help, and that's not good.


When Kent complained about the swearing, that was taken a little
superficially.  Swearing isn't really the Big Problem.  He was really
asking: "Can you start describing the problem more precisely so we can get
to work helping you?"

We just want to make sure the goal structure of questions on Tutor doesn't
lean toward: "I don't know what I'm doing, and the buggy system sucks, and
I'm so angry that I want people to sympathize with my anger."

Rather: "I don't know what I'm doing, here's what I've done so far, and I
hope I wrote enough information for people to help me."


Best of wishes!
_______________________________________________
Tutor maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/tutor