Fixed a bug where the answer was deemed incorrect if it had uppercase letter in the .tst file

This commit is contained in:
Zdenek Borovec 2019-10-21 16:47:23 +02:00
commit e5467ba459
3 changed files with 40 additions and 29 deletions

Binary file not shown.

View file

@ -3,6 +3,8 @@ from tkinter import filedialog
from tkinter import messagebox from tkinter import messagebox
import random import random
import time import time
import multiprocessing
import sys
def swapSides(): # prohodi sloupce v souboru testu (a tim i zmeni co je otazka a co odpoved) def swapSides(): # prohodi sloupce v souboru testu (a tim i zmeni co je otazka a co odpoved)
@ -53,6 +55,7 @@ def on_closing(): #zobrazi se pri zavirani programu, pokud se uzivatel rozhodne
def submitAnswer(uselessArgument): # precte pole pro zadani odpovedi, zhodnoti ji, a vhodnym zpusobem zmeni score a highscore def submitAnswer(uselessArgument): # precte pole pro zadani odpovedi, zhodnoti ji, a vhodnym zpusobem zmeni score a highscore
global score global score
for i in test[1][questionPlace]: for i in test[1][questionPlace]:
if answerEntry.get().lower() == i.lower(): if answerEntry.get().lower() == i.lower():
score += timeMultiplier score += timeMultiplier
@ -63,6 +66,7 @@ def submitAnswer(uselessArgument): # precte pole pro zadani odpovedi, zhodnoti j
if score > test[2]: if score > test[2]:
test[2] = score test[2] = score
highScore.set('High score: %s' % (test[2])) highScore.set('High score: %s' % (test[2]))
answerEntry.delete(0, 'end') answerEntry.delete(0, 'end')
newQuestion() newQuestion()
currentScore.set('Score: %s' % round(score, 2)) currentScore.set('Score: %s' % round(score, 2))
@ -100,9 +104,11 @@ def openTest(): # ziska adresu testu a nastavi seznam test aby byl novy test, po
gotfile = False gotfile = False
filepath = None filepath = None
while not gotfile: while not gotfile:
filepath = filedialog.askopenfilename(title='Select test file') filepath = filedialog.askopenfilename(title='Select test file', initialdir="///tests")
if getExtension(filepath) == '.tst': if getExtension(filepath) == '.tst':
gotfile = True gotfile = True
elif getExtension(filepath) == None:
pass
else: else:
messagebox.showinfo("ERROR: unrecognized file", "We are sorry but files with the '%s' appendix are not supported, we support only '.tst' files." % (getExtension(filepath))) messagebox.showinfo("ERROR: unrecognized file", "We are sorry but files with the '%s' appendix are not supported, we support only '.tst' files." % (getExtension(filepath)))
test = list(formatTest(filepath)) test = list(formatTest(filepath))
@ -125,14 +131,16 @@ def makeRoot(): # vytvori hlavni okno
root.geometry('500x400') root.geometry('500x400')
root.title('Test Me') root.title('Test Me')
root.configure(bg="gray") root.configure(bg="gray")
root.iconbitmap('programfiles/icon.ico') root.iconbitmap('icon.ico')
return root return root
multiprocessing.freeze_support()
root = makeRoot() root = makeRoot()
filepath = 'programfiles/default.tst' filepath = 'default.tst'
test = list(formatTest('programfiles/default.tst')) test = list(formatTest('default.tst'))
questionPlace = 0 questionPlace = 0
score = 0.0 score = 0.0
@ -179,4 +187,7 @@ while(running):
timeMultiplierLabel.configure(text='Your time bonus is: %s' % round(timeMultiplier, 2)) timeMultiplierLabel.configure(text='Your time bonus is: %s' % round(timeMultiplier, 2))
except: except:
None None
try:
root.update() root.update()
except:
pass

BIN
vyzkousejme.exe.lnk Normal file

Binary file not shown.