[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Ideas about storing questions/answers for a boardGame.



This is what I was going to suggest, for a way of storing questions in plain text format. You could add additional info like a category by specifying that, say, the second line in each block is the category.

<code>
f = open("questions.txt","r")
text = f.read()
c.close()
paras = text.split("\n\n")
questions = []
for para in paras:
	lines = [line for line in para.split("\n") if line and line[0] != "#"]
	question = lines[0]
	answers = lines[1:]
	questions.append((question,answers))
</code>

Then you can just have a text file like so:

# Lines starting with # are ignored
What is your name?
Arthur
Lancelot
Galahad

What is your quest?
I seek the Holy Grail
I seek a shrubbery
## Specify African/European?
I seek an unladen swallow

What is your favorite color?
Red
Blue
Yellow


Just be sure that the first line of every block of lines is the
question, and that every pair of questions is separated by one blank line.