<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>
Thanks for your reply Alan.<BR>
<BR>
Reorganizing the data into a dictionary format, not sure i understood your structure below, but understood the need to reorg my data into dictionaries.<BR>
<BR>
Was wondering it would work if i created two dictionaries;<BR>
<BR>
One say,... results, the other questions. Reorganizing the data something like this. Using an alpha key for the results, and a numeric key for the questions.<BR>
<BR>
If i go to this kind of format, would i a be able to still use random code with it effectively?, as i mix and max dictionary events.<BR>
<BR>
random.choice .. only seemed to give me the key and not the definition... not sure how to phrase that code.<BR>
<BR>
The learning continues... thanks again.<BR>
<BR>
If this structure would lend itself to what i'm trying to do,.. will then try and rebuild the questions into the structure.<BR>
<BR>
questions = {"111":"Army,Navy or Air Force",\<BR>"112":"Leave the Service, Get Desk Job, Become trainer",\<BR>"113":"etc1?",\<BR>"114":"etc2?",\<BR>}<BR>
results = {"aaa":"You die",\<BR>"aab":"You are wounded",\<BR>"aac":"You lose a leg",\<BR>"aad":"You lose an eye",\<BR>"aae":"You lose an arm",\<BR>"aaf":"You are awarded the bronze star",\<BR>"aag":"You are promoted to General",\<BR>"aah":"You ship sinks",\<BR>"aag":"You are busted out of the army",\<BR>"aah":"You plane is shot down",\<BR>}<BR>
<BR>
<BR>---<BR>> <BR>> Message: 7<BR>> Date: Sat, 14 Jul 2007 20:38:58 +0100<BR>> From: "Alan Gauld" <alan.gauld@btinternet.com><BR>> Subject: Re: [Tutor] Newbie Project part 2...<BR>> To: tutor@python.org<BR>> Message-ID: <f7b8pb$igs$1@sea.gmane.org><BR>> Content-Type: text/plain; format=flowed; charset="iso-8859-1";<BR>> reply-type=original<BR>> <BR>> <BR>> "Tony Noyeaux" <tnoyeaux@msn.com> wrote in<BR>> ---------------------------------------------------------<BR>> import random<BR>> print "\t\t\t\tLife Simulator"<BR>> print "You have just turned 18 years old. Your life awaits,... choices <BR>> to be made.."<BR>> print "\na)Army,\nb)Navy,\nc)Airforce"<BR>> job=raw_input("What will u join?")<BR>> if job == "a":<BR>> print random.choice(["You win Silver star", "You are killed in <BR>> action"])<BR>> elif job == "b":<BR>> print random.choice(["You fall overboard", "You command you're own <BR>> battleship"])<BR>> elif job == "c":<BR>> print random.choice(["You get shot down", "You become wing <BR>> commander"])<BR>> <BR>> raw_input("\n\nPress Enter to quit.")<BR>> ----------------------------------------------------------------------<BR>> <BR>> > This works fine.<BR>> ><BR>> > I am having trouble coding in the 2nd question,.. and all subsequent <BR>> > questions.<BR>> ><BR>> > The next Question.. has to be a result of the random result.<BR>> <BR>> I suggested using a nested dictionary structure to hold the questions.<BR>> Did you try that? It should make this a relatively trivial problem.<BR>> <BR>> I'll show the structure for the example you have given so far:<BR>> <BR>> questions: {'Q':<BR>> {"""<BR>> You have just turned 18 years old.<BR>> Your life awaits,... choices to be made..<BR>> """ : ['Army', 'Navy', 'Airforce']}<BR>> {'a':<BR>> { 'Q': {#army questions here}<BR>> }<BR>> 'b':<BR>> {<BR>> 'Q': {''What kind of ship?': <BR>> ['battleship','carrier','tug']},<BR>> 'a': { # battleship questions},<BR>> 'b': { # carrier questions},<BR>> 'c': { # tug questions }<BR>> }<BR>> 'c':<BR>> { 'Q': {# airforce Q here}<BR>> }<BR>> }<BR>> <BR>> Obviously keeping the structure clear is critical to success and<BR>> a good programmers editor will help balance the braces/quotes etc<BR>> <BR>> You can extend the structure to have multiple questions at each<BR>> stage by simply putting each questoon/answer dictionary in a list.<BR>> You could also break the structure to ease layout so for example<BR>> three separate instances, one per service. You could<BR>> even encapsulate it in a class (I would!)<BR>> <BR>> You are essentially building a tree structure and then navigating<BR>> down it in a part-random, part-deterministic manner.<BR>> <BR>> -- <BR>> Alan Gauld<BR>> Author of the Learn to Program web site<BR>> http://www.freenetpages.co.uk/hp/alan.gauld<BR>> <BR>> <BR>> <BR>> <BR>> ------------------------------<BR>> <BR>> _______________________________________________<BR>> Tutor maillist - Tutor@python.org<BR>> http://mail.python.org/mailman/listinfo/tutor<BR>> <BR>> <BR>> End of Tutor Digest, Vol 41, Issue 56<BR>> *************************************<BR><BR><br /><hr />PC Magazine’s 2007 editors’ choice for best web mail—award-winning Windows Live Hotmail. <a href='http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HMWL_mini_pcmag_0707' target='_new'>Check it out!</a></body>
</html>