[Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress
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 - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress
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
Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress
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 knowledgeWhich is not very encompassing,anyway. 2007/1/20, Karl Wittgenstein <[EMAIL PROTECTED]>: 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: > > >
Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress
"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 <[EMAIL PROTECTED]>: 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 knowledgeWhich 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 - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress
Sorry for the swear words... 2007/1/20, Kent Johnson <[EMAIL PROTECTED]>: 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 - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress
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 <[EMAIL PROTECTED]>: 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 - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor