Ejemplo n.º 1
0
class MyForm(QtGui.QMainWindow):
    
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.db = ComicsDB('data.db')
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.score = 0
        self.ui.label.setText("Score : %d" % self.score)
 

    def checkAnswer(self, x):
        x = x - 1
        if x == self.t:
            self.score = self.score + 1
            self.ui.label.setText("Score : %d" % self.score)
            self.load()
        else:
            self.ui.textEdit.setText("Your Answer is not correct, please try again or hit reload to change question.")
        
    def load(self):
        id = random.randrange(1,842,1)
        alt = "Alt Text : " + self.db.getAlt(id)
        titlet = self.db.getTitle(id)
        title = [self.db.getTitle(random.randrange(1,840,1))]
        for i in range(1,5):
            title.append(self.db.getTitle(random.randrange(1,840,1)))
        self.t = random.randrange(0,5,1)
        title[self.t] = titlet
        self.ui.retranslateUi(self, title[0], title[1], title[2], title[3], title [4])
        self.ui.textEdit.setText(alt)
Ejemplo n.º 2
0
#

from database import ComicsDB
import os
import random
import sys

DOCUMENTATION = ""

check = os.path.isfile('data.db')
if (check):
    cdb = ComicsDB('data.db')
    score = 0
    id = random.randrange(1,840,1) #fix
    alt = cdb.getAlt(id)
    title = cdb.getTitle(id)
    print "Alt Text : %s" %alt
    t = random.randrange(1,6,1) #fix
    ch = 1;
    for i in range(1,6):
        rand = random.randrange(1,840,1) #fix
        if (i != t):
            if (rand != id):
                print "%d %s" %(i, cdb.getTitle(rand))
        else:
            print "%d %s" %(t, title)
    while True:
        ans = raw_input('Pick the correct answer : ')
        if (int(ans) == t) :
            print "Answer is correct"
#            score = + 1;