project - trivia game

Ramsey Nasser aladameh at gmail.com
Wed Dec 5 02:04:04 EST 2007


Shawn,

First of all, next time try and isolate the problem yourself and send
a short snippet of code demonstrating the behavior you're having
trouble with. This makes it easier for other people to understand what
is going on and help you in a more focused way.

On Dec 5, 2007 2:43 AM, Shawn Minisall <trekker182 at comcast.net> wrote:
> For my final project, I'm trying to do a GUI based game similar to are

which GUI toolkit are you using?

> you smarter then a 5th grader.  I've been working on it and am stuck
> with some code someone helped me with to randomize the A,B,C,D letters
> that the correct answer is assigned too.  The code that does this is
> highlighted in bold and the code that assigns it to a variable is also
> in bold so I can test it in the console window.  Problem is, it's always
> stuck at letter A and doesn't always give the correct answer.  The
> correct answer is always position 1 in my make math question list.
> Could someone please help?

Your randomization code works. There are two issues that are causing
your problem, though.

1. You provide no mechanism to keep track of what answers are
"correct." In the whole program, there is no notion of whether an
answer is right or wrong. So you can't expect to get the "correct"
answer to a question without telling the machine which one it is.
Although it may start out at position 1, this is lost after
randomization.

2. Your program is hardcoded to always pick letter A

pResult = (currentScreen[0].getText())
print pResult

cResult = (currentScreen[2].getText())
print cResult

Following the definition of drawQuestion, currentScreen[0] will
contain entchoice which has text 'A', and currentScreen[2] will always
contain answer A and the first answer in the list, regardless of
whether or not it is correct (again, the machine has no way of
knowing). I'm not completely sure what you're trying to do here
(pResult, cResult...problemResult, correctResult?), so some more
explanation would help.

Also, some general comments:

#Picks random question
qNum = randrange(0, len(currentList))
qList = currentList[qNum]

can be replaced with

qList = choice(currentList)

(you would have to replace currentList.pop(qNum) with
currentList.remove(qList) )

aList = []
tmpList = qList[1:5]

#Randomizes answers
while(len(tmpList) > 0):
   rNum = randrange(0, len(tmpList))
   aList.append(tmpList[rNum])
   tmpList.pop(rNum)

can be replaced with

aList = qList[1:5]
shuffle(aList)

> thanks
>
> BTW, to whoever asked me why I don't use functions b4, I'm using them
> now that I've learned how to... :P ;)

Probably a good idea :)

Good luck with everything
-- 
nasser



More information about the Python-list mailing list