×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    1

    Question 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(rectpt):

         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 (
    rectanglenotein keyPairs:
            if 
    isInside(pointrectangle):
                return 
    note
        
    return default

    def makeColoredRect(cornerwidthheightcolorwin):

        
    corner2 corner.clone()  
        
    corner2.move(width, -height)
        
    rect Rectangle(cornercorner2)
        
    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
    (cornerwidthheightcolorwin):

        
    corner2 corner.clone()  
        
    corner2.move(width, -height)
        
    rect Rectangle(cornercorner2)
        
    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)):
            
    QuestionText(Point(350,200), Aquestions[q])
            
    Question.draw(win)
            
    Correct Button(Point(100,500), 200, -50'Red'win)
            
    textCorrect Text(Point(200525),Acorrect[q])
            
    textCorrect.draw(win)
            
    Wrong1 Button(Point(100,600), 200, -50'Red'win)
            
    textWrong1 Text(Point(200625),Awrong[q][0])
            
    textWrong1.draw(win)
            
    Wrong2 Button(Point(400,500), 200, -50'Red'win)
            
    textWrong2 Text(Point(500525),Awrong[q][1])
            
    textWrong2.draw(win)
            
    Wrong3 Button(Point(400,600), 200, -50'Red'win)
            
    textWrong3 Text(Point(500625),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(350200),"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(350200),"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(350200),"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(350200),"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)):
            
    QuestionText(Point(350,200), Mquestions[q])
            
    Question.draw(win)
            
    Correct Button(Point(100,500), 200, -50'Red'win)
            
    textCorrect Text(Point(200525),Mcorrect[q])
            
    textCorrect.draw(win)
            
    Wrong1 Button(Point(100,600), 200, -50'Red'win)
            
    textWrong1 Text(Point(200625),Mwrong[q][0])
            
    textWrong1.draw(win)
            
    Wrong2 Button(Point(400,500), 200, -50'Red'win)
            
    textWrong2 Text(Point(500525),Mwrong[q][1])
            
    textWrong2.draw(win)
            
    Wrong3 Button(Point(400,600), 200, -50'Red'win)
            
    textWrong3 Text(Point(500625),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(350200),"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(350200),"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(350200),"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(350200),"Wrong")
                
    textNo.draw(win)
                
    win.getMouse()
                
    textNo.undraw()


    def AnsButton(cornerwidthheightcolorwinlabel):
        
    ''' Return a Rectangle drawn in win with the upper left corner
        and color specified.'''

        
    corner2 corner.clone()  
        
    corner2.move(width, -height)
        
    rect Rectangle(cornercorner2)
        
    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.543.75), 525, -87.5'Red'win)
        
    textAdd Text(Point(35087.5),'Add')
        
    textAdd.draw(win)
        
    Multiply makeColoredRect(Point(87.5437.5), 525, -87.5'Purple'win)
        
    textMultiply Text(Point(350481.25),'Multiply')
        
    textMultiply.draw(win)
        
    clickwin.getMouse()
        
        
    Add.undraw()
        
    textAdd.undraw()
        
    Multiply.undraw()
        
    textMultiply.undraw()

        if 
    inside (Addclick):
         
            
    StartAdd()
                     
        
    elif inside(Multiplyclick):
            
    StartMultiply()

    main() 

  2. #2
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    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
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

Similar Threads

  1. Random number generation!!!
    By symbee in forum Symbian
    Replies: 16
    Last Post: 2009-04-24, 11:02
  2. WML & WMLSCript problem ????
    By gemini_shooter in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-14, 06:02
  3. WML & WMLSCript problem ????
    By gemini_shooter in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-14, 06:01
  4. stop after random number of http-requests on series60
    By sebflash in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2004-07-02, 16:48
  5. Personal
    By JSmith77 in forum PersonalJava
    Replies: 4
    Last Post: 2003-07-30, 12:52

Posting Permissions

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