Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (43 sloc) 1.6 KB
import sqlite3
class Car():
def __init__(self, make, model, rego):
self.make = make
self.model = model
self.rego = rego
def description(self):
print(f"You have entered in the following: {self.make} {self.model} with the rego {self.rego}")
newCar = Car
def main():
createDB = input("Create new Database = n | Add to existing Database = a | Select from database = s: ").lower()
if createDB == 'n':
newDatabase()
elif createDB == 'a':
newCar.make = input("Please enter in the make: ")
newCar.model = input("Please enter in the model: ")
newCar.rego = input("Please enter in the rego: ")
newCar.description(newCar)
database()
elif createDB == 's':
selectRego = input("What rego do you want to look up?: ")
conn = sqlite3.connect('carRego_db.sqlite')
cur = conn.cursor()
cur.execute(f'SELECT * FROM cars WHERE rego="{selectRego}"')
data = cur.fetchall()
print(data)
main()
else:
print("Error!")
def database():
conn = sqlite3.connect('carRego_db.sqlite')
cur = conn.cursor()
cur.execute(f'INSERT INTO cars (make, model, rego) values ("{newCar.make}", "{newCar.model}", "{newCar.rego}")')
conn.commit()
conn.close()
main()
def newDatabase():
dbname = input("What is your databse called? ")
conn = sqlite3.connect(f'{dbname}.sqlite')
cur = conn.cursor()
cur.execute(f'CREATE TABLE {dbname} (make VARCHAR, model VARCHAR, rego VARCHAR PRIMARY KEY)')
main()
main()
You can’t perform that action at this time.