diff --git a/challenges139-145/BookInfo.db b/challenges139-145/BookInfo.db new file mode 100644 index 0000000..f25aa2d Binary files /dev/null and b/challenges139-145/BookInfo.db differ diff --git a/challenges139-145/challenge-143_.py b/challenges139-145/challenge-143_.py new file mode 100644 index 0000000..e22c46e --- /dev/null +++ b/challenges139-145/challenge-143_.py @@ -0,0 +1,15 @@ +import sqlite3 + +with sqlite3.connect("BookInfo.db") as db: + cursor=db.cursor() + +selectionyear=int(input("Enter a year: ")) +print() + +cursor.execute("""SELECT Books.Title, Books.DatePublished, Books.Author +FROM Books WHERE DatePublished >? ORDER BY DatePublished""", [selectionyear]) + +for x in cursor.fetchall(): + print(x) + +db.close() \ No newline at end of file diff --git a/challenges139-145/challenge-144_.py b/challenges139-145/challenge-144_.py new file mode 100644 index 0000000..69c0043 --- /dev/null +++ b/challenges139-145/challenge-144_.py @@ -0,0 +1,23 @@ +import sqlite3 + +file = open("Booklist.txt","w") + +with sqlite3.connect("BookInfo.db") as db: + cursor=db.cursor() + +cursor.execute("SELECT Name from Authors") +for x in cursor.fetchall(): + print(x) + +print() +selectauthor=input("Enter an author's name: ") +print() + +cursor.execute("SELECT * from Books WHERE Author=?", [selectauthor]) +for x in cursor.fetchall(): + newrecord=str(x[0])+" - "+x[1]+" - "+x[2]+" - "+str(x[3])+"\n" + file.write(newrecord) + +file.close() + +db.close() \ No newline at end of file diff --git a/challenges139-145/challenge-145_.py b/challenges139-145/challenge-145_.py new file mode 100644 index 0000000..fab2033 --- /dev/null +++ b/challenges139-145/challenge-145_.py @@ -0,0 +1,46 @@ +import sqlite3 +from tkinter import * + +def addtolist(): + newname=sname.get + newgrade=sgrade.get + cursor.execute("INSERT INTO Scores (name,score) VALUES (?,?)", (newname,newgrade)) + db.commit() + sname.delete(0,END) + sgrade.delete(0,END) + sname.focus() + +def clearlist(): + sname.delete(0,END) + sgrade.delete(0,END) + sname.focus() + +with sqlite3.connect("TestScore.db") as db: + cursor=db.cursor() + +cursor.execute("""CREATE TABLE IF NOT EXISTS Scores( + id integer RIMAY KEY, name text, score integer);""") + +window=Tk() +window.title("TestScores") +window.geometry("450x200") + +label1=Label(text="Enter student's name: ") +label1.place(x=30, y=35) +sname=Entry(text="") +sname.place(x=150, y=35, width=200, height=25) +sname.focus() + +label2=Label(text="Enter student's grade: ") +label2.place(x=30, y=80) +sgrade=Entry(text="") +sgrade.place(x=150, y=80, width=200, height=25) +sgrade.focus() + +addbtn=Button(text="Add", command=addtolist) +addbtn.place(x=150, y=120, width=75, height=25) +clearbtn=Button(text="Clear", command=clearlist) +clearbtn.place(x=250, y=120, width=75, height=25) + +window.mainloop() +db.close \ No newline at end of file