Is it possible to make a set in an sqlite3 table a variable on python? -
this brief:
the teacher wants use results students taking these quizzes log performance. system should store last 3 scores each student. teacher able output results of quiz particular class, sorted:
- in alphabetical order each student’s highest score tests
- by highest score, highest lowest
- by average score, highest lowest.
analyse requirements in detail program , design, code, test , evaluate program allow teacher select class group @ , field use when sorting output data.
i thought doesn't work:
import sqlite3 new_db = sqlite3.connect('quiz.db') c = new_db.cursor() print "sort alphabetically" print "" c.execute("select * scores order name ") new_db.commit() row in c: print row print "" print "sort score" print "" c.execute("select * scores order -score3, score2, score1 ") new_db.commit() row in c: print row newscore = int(input('enter newest score: ') c.execute("update scores set name=?, score1=?, score2=? score3=?", (name, score2, score3, newscore)) c.execute("select * scores") row in c: print row new_db.commit() new_db.close() this says:
c.execute("update scores set name=?, score1=?, score2=? score3=?",(name, score2, score3, newscore)) nameerror: name 'name' not defined the table has been made not that
your error has nothing question's title, nor sql. try use variables (name, score2 , score3) not defined, python raises nameerror exception. have define these variables before using them.
this set aside, there quite few other issues script, first , main 1 being update query: if don't specify where clause update all existing records in table. in relational db schema, each table must have primary key (a field or combination of fields uniquely , unambiguously identify 1 single row). if don't have one, have create it, , need use in where clause if want update 1 give row.
Comments
Post a Comment