[Tutor] Help - Using Sort and Join

Daniel Gulko dangulko at hotmail.com
Mon Oct 22 21:57:12 CEST 2012

Hi Python Tutor,

I have an issue trying to figure out how to print out final answers using sort and join functions.

Assignment Specification:
make a function that is a magic eight ball emulator. emulator will be a function that returns one of the possible answers. Make another function that runs the emulator over and over again until user wants to quit, printing answer each time. When user quits, present all answers that the user got again, but present them in alphabetical order. Use the join() function available for strings for this.

Below is an example output from my code:

ask a question (or press 'enter' to quit): will I be rich
You may rely on it.

ask a question (or press 'enter' to quit): will I be poor
It is decidedly so.

ask a question (or press 'enter' to quit): why is that
Better not tell you now.

As my code is written when user presses enter I simply break and print this current output:
Have a nice day

What I want is when user exits for my code to take all previous answers, joining them and sorting them like below:
ask a question (or press 'enter' to quit):
You may rely on it. It is decidedly so. Better not tell you now.

My code works right now but I am missing the final part in how to join and sort all answers. Any suggestions or examples is helpful as I 
am very new with Python.

Current code is attached for viewing.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121022/03e6acac/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: MagicEightBall_ver2.py
URL: <http://mail.python.org/pipermail/tutor/attachments/20121022/03e6acac/attachment-0001.ksh>

More information about the Tutor mailing list