[Tutor] Python program with multiple answers

Patrick Sabin patrick.just4fun at gmail.com
Wed May 11 14:20:46 CEST 2011


  * 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 2011-05-11 12:49, Johnson Tran wrote:
> Hi Guys,
>
> 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. It will be continuous until the user says quit. My program works fine although I am trying to add something more to it, where when the user quits, it will present all the answers that the user got again and display them in alphabetical order...if anyone could point me in the right direction it'd be really helpful...my program so far is : (which works fine with no errros)
>
>
>
> 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")
> 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, 10)
> 		print dice[roll]
> 		raw_input()
> 	elif choice == "quit":
> 		True = 0
> 		raw_input()
> 	else:
> 		print "Error -- Try again\n"
>
>
>
>
>
> Thanks,
>
> JT
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list