Hi, can you help me complete this problem in Python? University Database A unive
ID: 647890 • Letter: H
Question
Hi, can you help me complete this problem in Python?
University Database
A university database has to keep track of various kinds of people. In particular:
- A Person has a name and a phone number
- An Employee is a Person who also has a salary
- A Student is a Person who also has a gpa
- A Staff is an Employee who also has a job title
- A Professor is an Employee who also has a course assigned to them
Here's a short main body of a program that creates a list of different kinds of people, and then prints out some information about each person, as well as some summary statistics about the people in the university:
----
# Create a list of people
People = [ Student("Sandy", "326-8324", 3.65), Student("Jordan", "632-7434", 3.1),
Professor("Leslie", "985-2363", 50000.00, "Info 501"),
Staff("Alex", "743-4638", 25000.00, "Editor") ]
# display information about our people
print "These are the people in the university:"
for person in People:
print person
# display the total salaries of all our employees and average GPA
# of all of our students
print
print "Our total university payroll budget is: " + str(Employee.total_salary)
print "Our average student GPA is: " + str(Student.mean_gpa())
----
As you can see, the main body assumes that there are classes called Person, Employee, Student, Professor, and Staff. Your task is to write the code for these classes, so that the main body code above displays the following output:
----
>>>
These are the people in the university:
Person Sandy has phone 326-8324
and is a Student with gpa 3.65
Person Jordan has phone 632-7434
and is a Student with gpa 3.1
Person Leslie has phone 985-2363
and is an Employee with salary 50000.0
and is a Professor assigned to class Info 501
Person Alex has phone 743-4638
and is an Employee with salary 25000.0
and is Staff with title Editor
Our total university payroll budget is: 75000.0
Our average student GPA is: 3.375
----
You can write whatever code you want inside the classes, but **you're not allowed to modify the main body**.
Make sure your code works even if we modify the People list to include more people.
Explanation / Answer
hope it helps you....
!/usr/bin/python
import MySdb
# Open database connection
db = MySdb.connect("localhost","testuser","test123","TESTDB" )
# prepare a cursor object using cursor() method
cursor = db.cursor()
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
# Create table as per requirement
sql = """CREATE TABLE EMPLOYEE (
FIRST_NAME CHAR(20) NOT NULL,
LAST_NAME CHAR(20),
AGE INT,
SEX CHAR(1),
INCOME FLOAT )"""
cursor.execute(sql)
# disconnect from server
db.close()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.