Python quiz, using tkinter -


from tkinter import * import tkinter tk  q = 0 s = -1 count = 0 correct = 0 incorrect = 0  question = ["is quiz","are sure","dont be","see not quiz"]  answer = ["yes","yes","ok","ok"] answer_cap = ["yes","yes","ok","ok"]  root = tk()  name = tk.label(root,text = "gui quiz") name.pack()  label = tk.label(root,text = question[0]) label.pack()  entry = tk.entry(root) entry.pack()    def out():     global q,correct,incorrect,s,count     count = count + 1     ans = entry.get()     print (ans)     print (question[q])     print (answer[q])     if count < 4:           if answer[q] or answer_cap[q] == ans :               q = q + 1               entry.delete(0, end)               correct = correct + 1               label.config(text = question[q])           else:               q = q + 1               entry.delete(0, end)               incorrect = incorrect + 1               label.config(text = question[q])     else:         entry.delete(0, end)         label.config(text = "correct: "+str(correct) + " incorrect:   "+str(incorrect))   def stop():     global q,correct,incorrect     q = 0     correct = 0     incorrect = 0     entry.delete(0, end)     label.config(text = question[0])  button = tk.button(root,text = "submit",command = out) button.pack()  button_two = tk.button(root,text = "restart",command = stop) button_two.pack()   root.mainloop()    

nothing wrong code how i'm doing it. when run module ask 4 questions , give answer, no matter put got 3 correct , none wrong. missing obvious or how layed out code.

the first part of out function should not have 'count = count + 1' because adds 1 score regardless of weather right or wrong; relocate commented code.

def out():     global q,correct,incorrect,s,count     #count = count + 1     ans = entry.get()     print (ans)     print (question[q])     print (answer[q]) 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -