vendredi 25 mars 2016

How to print a table based on an average of multiple scores (SQLite, Python)

I've been working on a program that asks a student to complete 10 mathematical questions, it then logs the users First name, Second name and Score based on their inputs at the beginning into a database using SQLite 3.

I would like the program to print a table based on the average score of all that students attempts at the quiz. For example, these two users average would be that of 8.5: http://ift.tt/1obqL4h.

I currently use tabulate 0.7.5 to handle the table method, as done here with the sorting by score:

if sort == "score":
       print("Accessing Database.")
       time.sleep(2)
       print("Accessing Database..")
       time.sleep(2)
       print("***Reading Complete***")
       con = lite.connect('students.db')
       with con:
           cur = con.cursor()
           table = cur.execute("SELECT FirstName, SecondName, Score  FROM Class1 ORDER BY Score DESC")
           print(tabulate(table, headers=["FirstName","SecondName", "Score"]))

I tried using a SQLite parameter to do it, but it just pasted a single average. I'd truly like a separate average that covers every attempt the student has made.

Any help would be much obliged!

Aucun commentaire:

Enregistrer un commentaire