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...
<br>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....<br><br>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.
<br><br>**** insert code ****<br>global altura_aeronave, largura_aeronave, comprimento_aeronave, comprimento, \<br> largura, altura<br><br>def compativel():<br> global altura, altura_aeronave, comprimento, comprimento_aeronave, \
<br> largura, largura_aeronave<br> if not largura <= largura_aeronave:<br> print 'Volume largo demais!'<br> elif not altura <= altura_aeronave:<br> print 'Volume alto demais!'
<br> elif not comprimento<=comprimento_aeronave:<br> print 'Volume comprido demais!'<br> <br>def define():<br> global largura, altura, comprimento<br> largura=input()<br> altura=input()
<br> comprimento=input()<br> <br>def porao():<br> global altura_aeronave, largura_aeronave, comprimento_aeronave<br> porao = input()<br> if porao == 1 :<br> altura_aeronave = 111<br> largura_aeronave = 112
<br> comprimento_aeronave = 211 #You originally had comprimento here?<br> return 1<br> elif porao == 4:<br> altura_aeronave = 112<br> largura_aeronave = 113<br> comprimento_aeronave = 212 #Same here
<br> return 1<br> else:<br> print "Porao inexistente!"<br><br><br>if porao():<br> define()<br> compativel()<br><br>*** end inserted code ***<br><br>HTH - Geoframer<br><br><div><span class="gmail_quote">
On 1/19/07, <b class="gmail_sendername">Geoframer</b> <<a href="mailto:geoframer@gmail.com">geoframer@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;">
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. :-) <br>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.
<br><br>*** Insert redone code ***<span class="q"><br>altura_aeronave = 0<br>largura_aeronave = 0<br>comprimento_aeronave = 0<br>comprimento = 0 <br>largura = 0<br>altura = 0<br><br></span>def compativel():<br> global altura, altura_aeronave, comprimento, comprimento_aeronave, \
<span class="q"><br> largura, largura_aeronave<br> if not largura <= largura_aeronave:<br> print 'Volume largo demais!'<br></span> elif not altura <= altura_aeronave:<br> print 'Volume alto demais!'
<br> elif not comprimento<=comprimento_aeronave:<br> print 'Volume comprido demais!'<br> <br>def define():<br> global largura, altura, comprimento<br> largura=input()<br> altura=input()
<br> comprimento=input()<span class="q"><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></span> return 1<span class="q"><br> elif porao == 4:<br> altura_aeronave = 112<br> largura_aeronave = 113<br> comprimento = 212<br></span> return 1<br>
else:<br> print "Porao inexistente!"
<br><br><br>if porao():<br> define()<br> compativel()<div><span class="e" id="q_1103ae5cd8e67d58_9"><br><br><div><span class="gmail_quote">On 1/19/07, <b class="gmail_sendername">Geoframer</b> <<a href="mailto:geoframer@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
geoframer@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;">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 :
<span><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></span>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
<span><br> comprimento = 211<br> elif porao == 4:<br></span> altura_aeronave = 112<br> largura_aeronave = 113<span><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></span>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<span><br> comprimento = input()<br> <br>#These are the comparison functions<br>def largura_compativel ():
<br></span> global largura, largura_aeronave
<span><br> if not largura <= largura_aeronave:<br> print 'Volume largo demais!'<br> <br>def altura_compativel ():<br></span> global altura, altura_aeronave<span><br> if not altura <= altura_aeronave:
<br>
print 'Volume alto demais!'<br> <br>def comprimento_compativel ():<br></span> global comprimento, comprimento_aeronave<span><br> if not comprimento<=comprimento_aeronave:<br> print 'Volume comprido demais!'
<br> <br>#Try to run this damn thing,man!!!!!1<br>porao()<br></span>#print altura_aeronave, largura_aeronave, comprimento<br>larguradef()<br>alturadef()<br>comprimentodef()<span><br>largura_compativel()<br>
altura_compativel<br>
comprimento_compativel()<br><br><br><br><br><br><br><br><br></span><div><div><span><span class="gmail_quote">On 1/19/07, <b class="gmail_sendername">Karl Wittgenstein</b> <<a href="mailto:miago.python@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
miago.python@gmail.com</a>
> wrote:</span></span></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><span><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></span></div>
<br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Tutor@python.org</a><br><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</a><br><br><br></blockquote></div><br>
</blockquote></div><br>
</span></div></blockquote></div><br>