[Tutor] python question
denis.spir at free.fr
Sat Nov 22 20:39:05 CET 2008
Some comments on your code, after David & Kent:
You have probably noticed that your programm repeats over and over the same
pattern, that could be called "process of a question". One major point of
programming is precisely to cope with such a repetitive task (this was true
even before electronics was invented with mechanical programms!).
The trick is to write down the overall pattern, and then use it each time it is
needed. It will build a kind of brick that you have to put inside a function to
be able to call it. Ask us if you need help or tips for that.
* main script
There seems to be a kind of script that guides the progression of your quizz
(esp. when music comes into play, sic:-)). This, not the repetition of
questions, can form the main part of your programm. From there would then be
called the question-process function.
If there is no real change instead, no progression, then this main prog simply
is a loop, as Kent says. You just need to define a way to get out of it!
Meaning when/why/how to quit the programm?
Both of these points lead you to *structure* your code. Presently your programm
is 'flat'; meaning it has not yet a shape that shows off its logic. When a
programm is properly organised, then its shape looks like what it does. And it
tells the reader -- yourself, first -- about it.
Get rid of all that mass of text! There are several ways to do that:
-1- Give each of your texts a name (Qn,An,...). Use these names to program the
logic. Associate a value to all of these names, creating 'constants', at e.g.
the head of your programm.
-2- Do the same, but in a separate file, called a 'module'. Then import this
module at start. If you need help for that, ask.
-3- When everything works good, then an interesting challenge may be to make
your set of texts be a real text file. Much better to manage and edit. You need
to write a fonction that is able to cope with a file, read it, analyse it,
properly process the data hidden in it...
Daniel J Kramer a écrit :
> I have just joined this list. I need some help working on a Python
> application I am working on. I am working on a quiz game where the users
> gain points when the answer questions correctly. I have written the
> skeleton of the quiz with If, Elif and Else statements. it runs perfectly.
> I am very unclear on how to score points at the end of each round and how to
> import images.
> Can anyone help out here or have any ideas on the best way to execute this?
> I have included a copy of the quiz so you can get an idea of what I am
> trying to do
> thank you so much and I look forward to hearing from you soon
More information about the Tutor