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.
Thanks,
Dan
import random
def AskMagicEightBall():
answers = ("As I see it, yes.",
"It is certain.",
"It is decidedly so.",
"Most likely.",
"Outlook good.",
"Signs point to yes.",
"Without a doubt.",
"Yes.",
"Yes definitely.",
"You may rely on it.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Do not count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful.")
return random.choice(answers)
def RunEmulator():
while True:
question = raw_input("ask a question (or press 'enter' to quit): ")
if question:
answers=AskMagicEightBall()
print answers
elif not question:
print "Have a nice day"
break
RunEmulator()
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor