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 ;-))
<br><br>***<br>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 :
<br><br>bla = 'Hello world'<br><br>def func():<br> global bla<br> print bla<br>***<br>If you do :<br>
porao = raw_input()<br>
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.<br>***<br>Now suppose you get the definitions using globals correct then you'll get new errors stating that an 'int' is not callable.<br>
This happens because you define for example altura as an integer and then also define a function called altura. If you now use :<br>altura()<br>It'll try to call the integer object and will fail.<br>Easy solution would be to make the function something like alturadef()
<br>***<br>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.<br>***<br>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 :
<br><br>#Ok,this is supposed to be a 2 option choice between values 1 and 4,<br>#i want the value to determine the variable values inside the function<br><br>altura_aeronave = 0<br>largura_aeronave = 0<br>comprimento_aeronave = 0
<br>comprimento = 0 <br>largura = 0<br>altura = 0<br><br>def porao():<br> global altura_aeronave, largura_aeronave, comprimento<br> porao = input()<br> if porao == 1 :<br> altura_aeronave = 111<br> largura_aeronave = 112
<br> comprimento = 211<br> elif porao == 4:<br> altura_aeronave = 112<br> largura_aeronave = 113<br> comprimento = 212<br> else:<br> print "Porão inexistente"<br>
<br>#These three functions were supposed to get input from user so it can be compared<br>#with the values determinated(determined?)above<br>def larguradef():<br> global largura<br> largura=input()<br><br>def alturadef():
<br> global altura<br> altura=input()<br><br>def comprimentodef():<br> global comprimento<br> comprimento = input()<br> <br>#These are the comparison functions<br>def largura_compativel ():<br> global largura, largura_aeronave
<br> if not largura <= largura_aeronave:<br> print 'Volume largo demais!'<br> <br>def altura_compativel ():<br> global altura, altura_aeronave<br> if not altura <= altura_aeronave:<br>
print 'Volume alto demais!'<br> <br>def comprimento_compativel ():<br> global comprimento, comprimento_aeronave<br> if not comprimento<=comprimento_aeronave:<br> print 'Volume comprido demais!'
<br> <br>#Try to run this damn thing,man!!!!!1<br>porao()<br>#print altura_aeronave, largura_aeronave, comprimento<br>larguradef()<br>alturadef()<br>comprimentodef()<br>largura_compativel()<br>altura_compativel<br>
comprimento_compativel()<br><br><br><br><br><br><br><br><br><div><span class="gmail_quote">On 1/19/07, <b class="gmail_sendername">Karl Wittgenstein</b> <<a href="mailto:miago.python@gmail.com">miago.python@gmail.com</a>
> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>Dear Smart Caring Dude,</div>
<div>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.
</div>
<div>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?</div>
<div>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.</div>
<div>Here goes the code:</div>
<div> </div>
<div>#Ok,this is supposed to be a 2 option choice between values 1 and 4,<br>#i want the value to determine the variable values inside the function<br>def porao():<br> porao = raw_input()<br> if porao == 1 :<br> global altura_aeronave = 111
<br> global largura_aeronave = 112<br> global comprimento = 211<br> elif porao == 4:<br> global altura_aeronave = 112<br> global largura_aeronave = 113<br> global comprimento = 212<br> else:
<br> print "Porão inexistente"<br>#These three functions were supposed to get input from user so it can be compared <br>#with the values determinated(determined?)above<br>def largura():<br> global largura=input()
<br>def altura():<br> global altura=input()<br>def comprimento():<br> global comprimento = input()<br>#These are the comparison functions<br>def largura_compativel ():<br> if not largura <= largura_aeronave:<br>
print 'Volume largo demais!'<br>def altura_compativel ():<br> if not altura <= altura_aeronave:<br> print 'Volume alto demais!'<br>def comprimento_compativel ():<br> if not comprimento<=comprimento_aeronave:
<br> print 'Volume comprido demais!'<br>#Try to run this damn thing,man!!!!!1<br>porao()<br>largura()<br>altura()<br>comprimento()<br>largura_compativel()<br>altura_compativel<br>comprimento_compativel()<br>
</div>
<br>_______________________________________________<br>Tutor maillist - <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Tutor@python.org">Tutor@python.org</a><br><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</a><br><br><br></blockquote></div><br>