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