[Tutor] Functions !
Tue, 28 Aug 2001 23:23:52 -0400 (EDT)
I have a question about functions. I hope I can ask this clearly (and get
a clear answer too!)
The last programming I did was in basic on my Commoidore 64 and functions
almost seem like what I remember as "subroutines"...
Im following a pretty good online tutorial called "Non-Programmers
Tutorial For Python
Anyway, Im reading through and typing in the examples. Below is one such
example and it works fine...
I dont understand the variables "c_temp" or "f_temp" since they are not
used anywhere else.
I am -guessing- that the part of the program that calls on the function is
sending a variable to be processed in the function and it is getting
dumped in c_temp or f_temp. If thats the case, they why is it that the
original variable is not used, in this case "temp"?
I'm guessing here too that many parts of a program with all their
different variables can call the funtion so no one absolute vaiable can be
used so this "dummy" (c_temp or f_temp) is used and I must therefore be
careful not to use the same label (variable) anywhere else in my program.
Im trying to follow the program (reading it) and understand what is
happening. It just wasnt clear where this 2 new lables came from and how
the program "knows" what is to be used there.
...Are my guess at least close? And would addeding "exit" at the end be
helpful in anyway?
#converts temperature to fahrenheit or celsius
print " 'p' print options"
print " 'c' convert from celsius"
print " 'f' convert from fahrenheit"
print " 'q' quit the program"
return (f_temp - 32.0)*5.0/9.0
choice = "p"
while choice != "q":
if choice == "c":
temp = input("Celsius temperature:")
elif choice == "f":
temp = input("Fahrenheit temperature:")
elif choice != "q":
choice = raw_input("option:")
David van Popering
Running slackware & Window Maker
"It has been established that having a really user friendly interface
makes it much too easy for aliens to take over the Enterprise."