Skip to content

Commit

Permalink
Adding pair programming 11
Browse files Browse the repository at this point in the history
  • Loading branch information
vitoriarlima committed Nov 12, 2021
1 parent fc4e157 commit 8e6e26a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Binary file added pair_programming/PP11/candidates
Binary file not shown.
18 changes: 18 additions & 0 deletions pair_programming/PP11/candidates.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
id|first_name|last_name|middle_name|party
33|Joseph|Biden||D
36|Samuel|Brownback||R
34|Hillary|Clinton|R.|D
39|Christopher|Dodd|J.|D
26|John|Edwards||D
22|Rudolph|Giuliani||R
24|Mike|Gravel||D
16|Mike|Huckabee||R
30|Duncan|Hunter||R
31|Dennis|Kucinich||D
37|John|McCain||R
20|Barack|Obama||D
32|Ron|Paul||R
29|Bill|Richardson||D
35|Mitt|Romney||R
38|Tom|Tancredo||R
41|Fred|Thompson|D.|R
28 changes: 28 additions & 0 deletions pair_programming/PP11/pp11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sqlite3

#create a database
db = sqlite3.connect("candidates")

cursor = db.cursor()

cursor.execute("""DROP TABLE IF EXISTS candidates""")

cursor.execute("""CREATE TABLE candidates (
id INTEGER PRIMARY KEY NOT NULL,
first_name TEXT,
last_name TEXT,
middle_initial TEXT,
party TEXT NOT NULL)""")

with open('candidates.txt') as f:
next(f)
for line in f:
uid, first_name, last_name, middle_initial, party = line.strip().split("|") #strip means that u take away the space at the end
cursor.execute("""INSERT INTO candidates
(id, first_name, last_name, middle_initial, party)
VALUES ( ?, ?, ?, ?, ?)""", (int(uid), first_name, last_name, middle_initial, party))


db.commit()
db.close()

0 comments on commit 8e6e26a

Please sign in to comment.