[Tutor] Python program with multiple answers

Johnson Tran aznjonn at me.com
Wed May 11 15:23:57 CEST 2011


Thanks for all the replies.  But, sorry I am getting a little confused. I have never created a list before and am not really sure where to start. If I put a "answer_list=[]" before the while True: line...is this correct? Or to go by Brett's method, how would I go about saving the questions and answers? If I am only trying to make a list of the answers, I probably do not need to save the questions ?

This is probably completely off but tried:

import random
dice = ("Without a doubt", "It is certain", "It is decidedly so","Yes", "For Sure", "No", "Dont count on it", "Try asking again","Reply hazy, try again", "Confucious says 'No'", "Better not tell you now","Cannot predict now","Concentrate and ask again","My reply is no","Outlook not so good","Very doubtful","Outlook is good","Most likely","As I see it, yes","I do not understand the question")
answer_list=[]
while True:
	choice = raw_input("Type 'ask' to ask a question. Type 'quit' to quit.\n")
	if choice == "ask":
		raw_input("Please enter your question:\n")
		roll = random.randint(0, len(dice))
		print dice[roll]
		raw_input()
	elif choice == "quit":
		True = 0
		raw_input()
	else:
		print "Error -- Try again\n"
	answer_list=???  <--not sure 
	answer_list.sort()
	print "Your answer's sorted:", answer_list

On May 11, 2011, at 5:57 AM, Brett Ritter wrote:


* Create a list.
* Each time, the user gets an answer add it to the list
* At the end of the program: sort the list and print each element of it

- Patrick



> On Wed, May 11, 2011 at 6:49 AM, Johnson Tran <aznjonn at me.com> wrote:
>> I've been working on a Python program where I create an 8 ball that will allow you to ask questions and will reply back with 20 possible answers.
> ...
>> if anyone could point me in the right direction it'd be really helpful
> 
> Answer cloudy, try again later [couldn't resist]
> 
> Patrick gave a decent summary. I'd suggest for learning purposes take
> each step at a time:
> 1) Save the questions, then once that works:
> 2) Save the corresponding answers, then
> 3) Print them, then
> 4) Sort them
> 
> That way if you encounter any problem it's limited in scope rather
> than trying to take it all in at once.
> -- 
> Brett Ritter / SwiftOne
> swiftone at swiftone.org





More information about the Tutor mailing list