Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program that accomplishes the following 1. imports race_horse module 2. Defines create_database function. This function takes no parameters. The function does

Write a Python program that accomplishes the following

1. imports race_horse module

 

2. Defines create_database function.  This function takes no parameters.  The function does the following:
a. Creates a database, horses
b. Returns a list containing the database connection object and the cursor object

 

3. Defines a create_table function.  This function takes two parameters; the connection and cursor objects returned from the create_database function.  This function does not return data.  The function accomplishes the following:
a. Creates a race_horse table in the horses database
i. Uses the cursor object to create the race_horse table with the following fields/columns
1. horse_name (varchar(25))
2. horse_color (varchar(15))
3. horse_b_year (varchar(4))
4. horse_races (varchar(4))
b. This function does not return data

     

4. Defines add_horses function.  This function adds the RaceHorse objects to the race_horse table.  This function takes three parameters: the database connection object, the cursor object, and a list containing RaceHorses as parameters. The function accomplishes the following:
a. Loop through the list of RaceHorses and add each object to the race_horse table.  To add an object to race_horse table, create and execute a query that uses the properties (horse_name,horse_color,horse_b_year, and horse_races) of the Object to set the column values in the race_horse table.  
b. This function does not return data

 

5. Defines a display_data function.  This function takes one parameter; the cursor object returned by the create_database function. This function does not return data.  The function accomplishes the following:
a. Execute query on the race_horse table for all rows
b. Loops through the result of the query and displays each row of the table

 

6. Defines a search_horse function.  This function takes the cursor object returned by the create_database function as parameter and the name of a horse to be searched. This function does not return data.  The function accomplishes the following:
a. Executes a query that searches the race_horse table for a horse with horse_name equal to the name passed to the function
b. Loops through the result of the query and displays each row in the query
Main Program

 

7. Call the create_database() function
a. Store the return data of the function
i. Store the database connection object into a variable
ii. Store the cursor object into a variable

Note: This function returns a list containing two items: the database connection object and the cursor object.  Each item in the returned list will be stored in a separate variable

 

8. Calls create_table() function
a. Pass the database connection object as argument
b. Pass the cursor connection object as argument

 

9. Creates a list of 5 RaceHorses
a. Create an empty list, horses_list
b. Use a while loop to prompt for the details of each RaceHorse
i. Create a RaceHorse object
ii. Add/Append the RaceHorse object to horses_list
iii. Exit the loop once 5 objects are added to the list

 

10. Calls the add_horses() function
a. Pass the horses_list as an argument
b. Pass the database connection object as argument
c. Pass the cursor object as argument

 

11. Call the display_data() function
a. Pass the cursor object as argument

 

12. Prompt the user to enter the name of a RaceHorse (At the prompt, enter the name of one of the RaceHorses added to the database by the add_horses() function)

 

13. Calls the search_horse() function
a. Pass the name entered in the previous step, as a parameter
b. Pass the cursor object as parameter

 

Example

Database Created

 

Table Created

 

Create a list of Race Horses:

 

Enter horse name: Sawehezi
Enter horse color: brown
Enter horse birth year: 1970
Enter horse races: 21

 

Enter horse name: Beholder
Enter horse color black
Enter horse birth year: 2010
Enter horse races: 26

 

Add the Race Horse to the database
Adding( Secretariat brown, 1970 21) to the database
Adding( Beholder black 2010 26 ) to the database

 

Display all race horses in the database:
( 'Secretariat', 'brown', '1970', '21' )
( 'Beholder' 'black', '2010', '26')

 

Prompt of a horse name


Enter horse name: Beholder

 

Display horse found:
('Beholder', 'black', '2010', '26')

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

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Databases questions