[Tutor] Some questions about my yen-USD.py

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Sep 8 06:39:09 CEST 2006


>> I'm looking at the last part of the main() function:
>> 
>> #################
>> def main():
>>      while True:
>>          ...
>>          again()
>>          if again:
>>              break
>> #################
>> 
>> This looks a little suspicious.  What does the again() function do, and 
>> is it supposed to return a value?
>
> Yes. It will return anything other than "y", "Y", etc., in answer to the 
> prompt, "\n\nDo you want to do another calculation? Y/N: ".


Hi Dick,

Are you sure?  When you say "it will return anything other than 'y', 'Y', 
what do you mean?  What's the return value of again()?


Just from a pure pattern matching perspective, compare what you had in the 
previous statements in terms of shape:

         rate = getRate()
         if str(rate) in "QqXx": break

or:

         currency = getYenOrUSD()
         if currency in "QqXx": break

versus the shape of the again block:

         again()
         if again:
             break

Do you see something about the "shape" of the third block that's different 
from the first two blocks?  That's what I'm trying to get at: there's 
something very different here.


Read Andrei's point 3 on again() again, and see if what he says makes 
sense to you.

     http://mail.python.org/pipermail/tutor/2006-September/049105.html

This is a point that you'll want to look at with scrutiny: even though the 
program looks like it's working, suspend your belief for the moment. 
*grin*


There's something funky happening in the control flow of the code around 
this area.  If you don't understand, ask for more clarification, and one 
of us here will be more explicit.

Just to be fair: what you have does work, from a purely technical 
perspective.  The thing is that it is not following the human intentions 
that you've written into the code, and other readers will get confused 
unless they stare at the code for a while.


Best of wishes!


More information about the Tutor mailing list