1. ## Random Number Generating

Ok. Newbie poster so bear with me. I created a beginner math program that should be usable by young children. I have it working for the most part but I would now like to create random questions and answers, rather than typing out the questions and answer individually as I have done. Also, for whatever reason the correct answer is always the top right button (You will see what i mean when running the program) If anyone could help me out that would be much appreciated. Thanks all!

PHP Code:
``` from graphics import * win = GraphWin('Choose', 700,700) def inside(rect, pt):      if (pt.getX() > rect.getP1().getX()) and (pt.getX() < rect.getP2().getX()) and (pt.getY() > rect.getP1().getY()) and (pt.getY() < rect.getP2().getY()):         return True            return False def getNoteFromGUI(keyPairs, default, win):          point = win.getMouse()     for (rectangle, note) in keyPairs:         if isInside(point, rectangle):             return note     return default def makeColoredRect(corner, width, height, color, win):     corner2 = corner.clone()       corner2.move(width, -height)     rect = Rectangle(corner, corner2)     rect.setFill(color)     rect.setWidth(2)     rect.setOutline("black")     rect.draw(win)     corner3 = corner.clone()     corner3.move(width/2, -height/2)     return rect      def Button(corner, width, height, color, win):     corner2 = corner.clone()       corner2.move(width, -height)     rect = Rectangle(corner, corner2)     rect.setFill(color)     rect.setWidth(2)     rect.setOutline("black")     rect.draw(win)     corner3 = corner.clone()     corner3.move(width/2, -height/2)     return rect def StartAdd():     Aquestions = ('what is 1+1','what is 2+1','what is 8+8')     Acorrect= (2,3,16)     Awrong = ((1,4,7),(3,5,4),(3,34,43))     for q in range(len(Aquestions)):         Question= Text(Point(350,200), Aquestions[q])         Question.draw(win)         Correct = Button(Point(100,500), 200, -50, 'Red', win)         textCorrect = Text(Point(200, 525),Acorrect[q])         textCorrect.draw(win)         Wrong1 = Button(Point(100,600), 200, -50, 'Red', win)         textWrong1 = Text(Point(200, 625),Awrong[q][0])         textWrong1.draw(win)         Wrong2 = Button(Point(400,500), 200, -50, 'Red', win)         textWrong2 = Text(Point(500, 525),Awrong[q][1])         textWrong2.draw(win)         Wrong3 = Button(Point(400,600), 200, -50, 'Red', win)         textWrong3 = Text(Point(500, 625),Awrong[q][2])         textWrong3.draw(win)                  click = win.getMouse()         if inside (Correct,click):             Correct.undraw()             textCorrect.undraw()             Wrong1.undraw()             textWrong1.undraw()             Wrong2.undraw()             textWrong2.undraw()             Wrong3.undraw()             textWrong3.undraw()             Yay = Button(Point(200,100), 300, -200, 'Red', win)             textYay = Text(Point(350, 200),"Good Job")             textYay.draw(win)             win.getMouse()             textYay.undraw()         if inside (Wrong1,click):             Correct.undraw()             textCorrect.undraw()             Wrong1.undraw()             textWrong1.undraw()             Wrong2.undraw()             textWrong2.undraw()             Wrong3.undraw()             textWrong3.undraw()             No = Button(Point(200,100), 300, -200, 'Red', win)             textNo = Text(Point(350, 200),"Wrong")             textNo.draw(win)             win.getMouse()             textNo.undraw()         if inside (Wrong2,click):             Correct.undraw()             textCorrect.undraw()             Wrong1.undraw()             textWrong1.undraw()             Wrong2.undraw()             textWrong2.undraw()             Wrong3.undraw()             textWrong3.undraw()             No = Button(Point(200,100), 300, -200, 'Red', win)             textNo = Text(Point(350, 200),"Wrong")             textNo.draw(win)             win.getMouse()             textNo.undraw()         if inside (Wrong3,click):             Correct.undraw()             textCorrect.undraw()             Wrong1.undraw()             textWrong1.undraw()             Wrong2.undraw()             textWrong2.undraw()             Wrong3.undraw()             textWrong3.undraw()             No = Button(Point(200,100), 300, -200, 'Red', win)             textNo = Text(Point(350, 200),"Wrong")             textNo.draw(win)             win.getMouse()             textNo.undraw() def StartMultiply():     Mquestions  = list(['what is 2 x 2','what is 3 x 3'])     Mcorrect= (4,9)     Mwrong = ((3,6,9),(2,4,6))     for q in range(len(Mquestions)):         Question= Text(Point(350,200), Mquestions[q])         Question.draw(win)         Correct = Button(Point(100,500), 200, -50, 'Red', win)         textCorrect = Text(Point(200, 525),Mcorrect[q])         textCorrect.draw(win)         Wrong1 = Button(Point(100,600), 200, -50, 'Red', win)         textWrong1 = Text(Point(200, 625),Mwrong[q][0])         textWrong1.draw(win)         Wrong2 = Button(Point(400,500), 200, -50, 'Red', win)         textWrong2 = Text(Point(500, 525),Mwrong[q][1])         textWrong2.draw(win)         Wrong3 = Button(Point(400,600), 200, -50, 'Red', win)         textWrong3 = Text(Point(500, 625),Mwrong[q][2])         textWrong3.draw(win)         click = win.getMouse()         if inside (Correct,click):             Correct.undraw()             textCorrect.undraw()             Wrong1.undraw()             textWrong1.undraw()             Wrong2.undraw()             textWrong2.undraw()             Wrong3.undraw()             textWrong3.undraw()             Yay = Button(Point(200,100), 300, -200, 'Red', win)             textYay = Text(Point(350, 200),"Good Job")             textYay.draw(win)             win.getMouse()             textYay.undraw()         if inside (Wrong1,click):             Correct.undraw()             textCorrect.undraw()             Wrong1.undraw()             textWrong1.undraw()             Wrong2.undraw()             textWrong2.undraw()             Wrong3.undraw()             textWrong3.undraw()             No = Button(Point(200,100), 300, -200, 'Red', win)             textNo = Text(Point(350, 200),"Wrong")             textNo.draw(win)             win.getMouse()             textNo.undraw()         if inside (Wrong2,click):             Correct.undraw()             textCorrect.undraw()             Wrong1.undraw()             textWrong1.undraw()             Wrong2.undraw()             textWrong2.undraw()             Wrong3.undraw()             textWrong3.undraw()             No = Button(Point(200,100), 300, -200, 'Red', win)             textNo = Text(Point(350, 200),"Wrong")             textNo.draw(win)             win.getMouse()             textNo.undraw()         if inside (Wrong3,click):             Correct.undraw()             textCorrect.undraw()             Wrong1.undraw()             textWrong1.undraw()             Wrong2.undraw()             textWrong2.undraw()             Wrong3.undraw()             textWrong3.undraw()             No = Button(Point(200,100), 300, -200, 'Red', win)             textNo = Text(Point(350, 200),"Wrong")             textNo.draw(win)             win.getMouse()             textNo.undraw() def AnsButton(corner, width, height, color, win, label):     ''' Return a Rectangle drawn in win with the upper left corner     and color specified.'''     corner2 = corner.clone()       corner2.move(width, -height)     rect = Rectangle(corner, corner2)     rect.setFill(color)     rect.setWidth(2)     rect.setOutline("black")     rect.draw(win)     corner3 = corner.clone()     corner3.move(width/2, -height/2)     l1 = Text(corner3,label)     l1.draw(win)     return rect def main():     Add = makeColoredRect(Point(87.5, 43.75), 525, -87.5, 'Red', win)     textAdd = Text(Point(350, 87.5),'Add')     textAdd.draw(win)     Multiply = makeColoredRect(Point(87.5, 437.5), 525, -87.5, 'Purple', win)     textMultiply = Text(Point(350, 481.25),'Multiply')     textMultiply.draw(win)     click= win.getMouse()          Add.undraw()     textAdd.undraw()     Multiply.undraw()     textMultiply.undraw()     if inside (Add, click):               StartAdd()                       elif inside(Multiply, click):         StartMultiply() main()  ```

2. ## Re: Random Number Generating

Sorry but I think that's not a source code compatible with Python for Symbian S60

This is a discussion board about Mobile Programming not about general Python programming

I suggest you asking to another Python Forums that you can find HERE

BR
Cyke64

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•