Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Anaconda Python, Spyder language used. Here is a start of a registration function that creates a connection to the database and inserts specific values into

Anaconda Python, Spyder language used.

Here is a start of a registration function that creates a connection to the database and inserts specific values into the DB. Be sure to read the comments for hints

and explanations. Be sure before you try this that you save the file in the same location you have saved your database file. Also note that EmployeeID is the

primary key for the Employee table and thus must be unique...if you try to insert the same EmployeeID more than once your program will crash.

------code-------

import sqlite3

conn = sqlite3.connect("OS_Employee.db")

with conn:

cur = conn.cursor()

try:

cur.execute("""INSERT INTO Employee VALUES

('1057', 'leslie', 'albert', 'leslie@asd.com', 'leslie')""")

cur.execute("SELECT * FROM Employee WHERE (EmployeeID = '1057')")

results = cur.fetchall()

print(results)

except:

print("Connection failed")

------code------

Whats left to do:

1. Alter the code above to take the 5 values from the user as input, add your error checking for blanks (while not StringName

2. Use the .strip, .lower, .title where appropriate (note: In the database, the first and last names start with capital letters, the rest are all lower case)

3. Include a loop that will catch a repeated EmployeeID to keep our project from crashing. To do this, take the EmployID from the user, execute a Count

query against the database to see if that particular id is already in use. If it has been used (count = 1) loop and ask for another id from the user. If the

count = 0 then continue with your Insert.

4. Be sure to provide helpful prompts and feedback to your users!

5. Once its all tested and working well, tuck all of your registration code into a function.

I got this working so far.

import sqlite3

conn = sqlite3.connect('OS_Employee.db')

def get_values():

emp_id()

firstname()

lastname()

email()

def email():

user_email = input("Please enter your email: ")

print(user_email)

def lastname():

l_name = input("Please enter your last name: ")

l_name = l_name.lower().strip(" ").title()

print(l_name)

def firstname():

f_name = input("Please enter your first name: ")

f_name = f_name.lower().strip(" ").title()

print(f_name)

return f_name

def emp_id():

while True:

try:

emp_id = int(input("Please enter your employee ID: "))

while len(str(emp_id)) != 4:

print("Employee ID can only be 4 digits in length!")

emp_id = int(input("Please enter your employee ID again: "))

break

except ValueError:

print("Enter only numbers.")

print(emp_id)

get_values()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago