(This repeats an earlier post of mine, and gives the correct link to the script I wrote about: <http://tutoree7.pastebin.com/nuCgpUpL>. In a subsequent post I reported that I had gotten rid of the flag in a further revision: <http://tutoree7.pastebin.com/qYVnhphx> This link is correct. I apologize for the confusion. --Dick)
On Wed, Jul 28, 2010 at 08:35, Richard D. Moores <rdmoo...@gmail.com> wrote: > Now I'll dig into all the help I received. I see an *args in Steven's > detailed reply. That'll take some reviewing to understand. Here's my slight revision of Steven's script (see my note, lines 9-14) -- revised only because I wanted it to handle the case where the user (me) entered the interval bounds in the wrong order, e.g., 10, 5 instead of 5, 10. I've also added a way ('r') for the user to choose to get another random number in the same interval without having to reenter the bounds: <http://tutoree7.pastebin.com/nuCgpUpL>. Then I needed a way ('c') to choose to change the bounds after 'r' had been used. I used a flag (lines 42, 53, 55) to accomplish these additions. Was there a better way? Should I have written a couple of extra functions instead of using the flag? Are flags unpythonic? I've learned a lot from his script, and hope to learn more -- I'm still grappling with the *args of line 46. What I've learned so far: 1. To separate the front end (for the user) from the back end. See his note on line 3. 2. The use of maxsplit with str.split(). Line 29. 3. Using the return of a function to call another function. Line 38. 4. In main(), he assigns the prompt to a variable _before_ the while loop (line 41), so the assignment is done only once, rather than each time through the loop. Not a biggie in this script, but a good thing to learn, I think. So thanks, Steven! Now, on to *args! Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor