Skip to content

Instantly share code, notes, and snippets.

@daniel-schroeder-dev
Created November 22, 2020 16:53
Show Gist options
  • Select an option

  • Save daniel-schroeder-dev/8449010789d72fd7ee8a864f46578baa to your computer and use it in GitHub Desktop.

Select an option

Save daniel-schroeder-dev/8449010789d72fd7ee8a864f46578baa to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import cgitb
cgitb.enable()
print("Content-type:text/html")
print()
######## E X E R C I S E S #########
#
# Exercise 1: Execute the query to show the marks of a student named Tom
# Exercise 2: Show separate lists of students who passed and the ones who failed.
# Exercise 3: Update the grade column based on the marks.
# Exercise 4: Add a grade A, A+, A- based on the marks.
# Bonus: Show the student with highest marks.
#
# Homework 1: Add the remaining grades using the update query.
# Also, arrange the table by Grade.
# - Add an update query to set the Grades column.
# - You can use any value for grading, or refer from the table given alongside.
# - Use and operator to check between a range of numbers
# - Use order by to sort the data by Grades.
#
# Homework 2: Execute queries to get:
# - Show student names and marks where marks are between 40 to 80.
# - List of student names and their marks who got less than 40 marks.
# - Name and marks of student with following names
# - Jon
# - Lisa
# - Dave
# Use or operator for condition in this query.
#############################
import sqlite3
connection = sqlite3.connect('database/school.db')
sql = connection.cursor()
from helper import showData
sql.execute('''
CREATE TABLE IF NOT EXISTS grading(
name TEXT,
score INTEGER,
grade TEXT
)''')
sql.execute('''INSERT INTO grading VALUES
("Jon", 65, "--"),
("Dave", 23, "--"),
("Thomas", 98, "--"),
("Max", 95, "--"),
("Tom", 58, "--"),
("Becky", 19, "--"),
("Penny", 91, "--"),
("Shreya", 30, "--"),
("Lisa", 60, "--"),
("George", 85, "--"),
("Rihana", 74, "--")
''')
data = sql.execute("SELECT * FROM grading")
showData(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment