Create a MySQL database that contains information about students in a university. Possible fields might include date of birth, major, current grade point average, credits earned, etc. Write a Py- thon program to manage the database. Include the following functionality: sort all students according to GPA (descending), create a display of all students in one particular major and remove all
records from the database where the student has the required amount of credits to graduate.
What will be an ideal response?
```
# The program connects to the students database and
# executes various queries based on user input.
import MySQLdb
userInput = None
# available database operations
queries = \
[ "SELECT name, gpa FROM students ORDER BY gpa DESC;",
"SELECT name, major FROM students WHERE major = \"%s\"",
"DELETE FROM students WHERE credits_earned >= 20" ]
connection = MySQLdb.connect( db = "students" )
cursor = connection.cursor()
# prompt user to enter menu option
while userInput != "7":
print "1. Execute query sorting the students by gpa."
print "2. Print query sorting the students by gpa."
print "3. Execute query selecting students by major."
print "4. Print query selecting students by major."
print "5. Execute query removing graduated students."
print "6. Execute query removing graduated students."
print "7. Quit"
userInput = raw_input( "? " )
print
if userInput in [ "1", "3", "5" ]:
# select students by major
if userInput == "3":
major = raw_input( "what major? " )
majorQuery = queries[ 1 ] % major
cursor.execute( majorQuery )
else:
# sort students by GPA or remove graduating students
cursor.execute( queries[ int( userInput ) / 2 ] )
print cursor.fetchall()
# print requested query information
if userInput in [ "2", "4", "6" ]:
print queries[ int( userInput ) / 3 ]
print
cursor.close()
conection.close()
```
1. Execute query sorting the students by gpa.
2. Print query sorting the students by gpa.
3. Execute query selecting students by major.
4. Print query selecting students by major.
5. Execute query removing graduated students.
6. Execute query removing graduated students.
7. Quit
? 1
(('Jack Smith', 3.831), ('Joe Doe', 3.7869999999999999), ('Jane Doe',
3.53100000
00000001), ('Jamie Smith', 3.331))
1. Execute query sorting the students by gpa.
2. Print query sorting the students by gpa.
3. Execute query selecting students by major.
4. Print query selecting students by major.
5. Execute query removing graduated students.
6. Execute query removing graduated students.
7. Quit
? 3
what major? computer science
(('Joe Doe', 'Computer Science'),)
1. Execute query sorting the students by gpa.
2. Print query sorting the students by gpa.
3. Execute query selecting students by major.
4. Print query selecting students by major.
5. Execute query removing graduated students.
6. Execute query removing graduated students.
7. Quit
? 7
You might also like to view...
Answer the following statements true (T) or false (F)
1. When a text file is created in Visual Basic using a StreamWriter, the extension .txt is automatically added to the file name if no other extension is specified. 2. In the following statement, sw is the name of a variable. ``` Dim sw As IO.StreamWriter = _ IO.File.CreateText("C:\TEXT FILES\INCOME Data.txt") 3. If an existing text file is opened for output, the computer will append any new data to the end of this existing file. 4. If the value of IO.File.Exists(filespec) is True, then the specified file exists. 5. An individual item of a text file cannot be changed or deleted directly. ```
To avoid confusion, set the width either with _____ width style or the HTML size attribute, but not both.
A. CIS B. CSS C. CGI D. PHP
In copying a binary tree, if you use just the value of the pointer of the root node, you get a ____ copy of the data.
A. static B. shallow C. deep D. local
What IIS feature consists of a group of DLL files that are applications and filters designed to improve IIS performance and increase integration with other programs?
A. Internet Server Application Programming Interface B. Internet Information Web Application Gateway C. Microsoft Common Gateway Interface Enhanced D. Web Services Integrated Application Controller