On 05/18/2016 06:50 PM, Jake Kobs wrote:
MRAB,
I am not quite sure how to return the print statements so I thought that
returning the displayInfo def would help.. Im so lost.
Why do you think you want to _return_ a print statement? The print statement _DOES_ the
printing, there is nothing that needs to be returned. Sometimes you might want to return a
_string_ to be printed where it was called from, but that's not what you want here.
You say that the display info isn't shown... It looks to me like it it isn't shown because your
program will crash. What you have here is called "infinite recursion":
displayInfo() calls displayInfo() which calls displayInfo() which calls displayInfo() which
calls ... and so on forever.
Another comment: Your getHigh() and getLow() functions are not necessary. Python already has
max() and min() functions built in to do this exact same thing. Instead you can use:
highPints = max(pints)
lowPints = min(pints)
Of course, writing your own versions as a leaning experience is good too. But I would suggest
that a for loop instead of a while in your version would be better. For one thing, it
eliminates the counter. My suggested version...
def getHigh(pints):
high = 0
for pint in pints:
if pint > high:
high = pint
return high
And getLow() is similar (but set the initial value to a high number).
The following example may be more advanced than you're ready for now, but you _might_ find it
worth studying. It's possible to do both in a single function:
def getMaxMin(pints):
high = low = pints[0] # Initialize high and low to the first value of
the array
for pint in pints[1:]: # Scan through the remainder of the pints array
if pint > high:
high = pint
if pint < low:
low = pint
return high, low
You would use it as:
highPints, lowPints = getMaxMin(pints)
I'm NOT necessarily recommending this, but just suggesting it as an example to
study.
Good luck with your Python studies. It's a great language to learn.
-=- Larry -=-
PS. A final thought...
I don't know your situation so this may not be reasonable but... I HIGHLY recommend switching
to Python 3 instead of 2. Version 2 is at "end-of-life" and won't be updated any further.
Version 3 is where all future development will occur. It is definitely the better version, and
while there are certainly differences, to a beginning programmer the learning curve will be the
same.
--
https://mail.python.org/mailman/listinfo/python-list