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

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



marta sanz wrote:
This game is aimed to be used by my sister's school teacher in her class of 10 years old kids. I said this because, despite the fact that I will give this game with some questions so they can play from the moment I give it to them, I would like the teacher to make her own question bank once the kids have learned the questions I give at the beginning, but have no idea of how can i do a simple bank and how can I access it from the pygame code.

Hi,

Someone else suggested XML, but personally that seems too heavyweight for a teacher (with possibly no computing experience) to edit. Here is what I would do:

1) create a directory called "questions"
2) each file in "questions" is a text file which has:

Question
--
Answer

Here's an example:

Who invented the Python programming language?
--
Guido van Rossum


You can list the files in a directory using the listdir function from the os module. To read this file and split it, I would do something like this:

f = file("question.txt")
contents = f.read()
question, answer = contents.split('--')

(If you try this in an interpreter, you'll see that you get question = 'Who invented the Python programming language?\n', answer = '\nGuido van Rossum\n'. You might call strip() on these strings.)

Hope this helps!

Ethan