Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Write a program that allows a user to display and duplicate tables. At the beginning of the program, some tables are imported from a separate module table_data.py that you must not modify.

Use the module tabulate to print tables in the expected format.

Main menu

The program prompt of the main menu looks like:

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

If the user inputs 1, 2, 3, 4, 5, 6, 7 or 0, it runs the corresponding menu option.

Assume that the user and the automated tests input a correct choice in the main menu.

We recommend you create a function for each menu option.

1. List tables

This menu option prints a table that lists the tables that currently exist in the program.

Index    Columns    Rows

-------  ---------  ------

0          5       6

1          4       7

2          3       4

3          3       6

After the header, there is one row per table, with its index, and the number of columns and rows of that table.

At the beginning of the program, all tables from the module table_data are shown in the list, which then looks exactly as shown above.

This list is updated as tables change. See example 1.

2. Display table

This menu option prints a table given its index.

The program prints Choose a table index (to display):. The user then selects a table by its index (as listed by menu option 1). See below.

Choose a table index (to display):

1

Student ID  First Name    Last Name    Grade Code

------------  ------------  -----------  ------------

798154  Brynhildr     Blakeley     N

134789  Felix         Li           N

798951  Paityn        Summers      P

465120  Turnus        Elliot       C

963245  Alysia        Jervis       D

469120  Muhammad      Saad         HD

If an incorrect table index is provided, the program prints Incorrect table index. Try again., and prints Choose a table index (to display): again, until a correct index is provided. See example 2.

For menu option 2 and future menu options, assume that, when asked to input a table index, the user inputs an integer.

3. Duplicate table

Similar to menu option 2, this menu option repeatedly asks the user to select a table, then creates a copy of that table. The index of the new table is the smallest index that has not previously been assigned to a table.

Choose a table index (to duplicate):

1

See example 3.

Examples

User inputs are in bold font below.

Example 1

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

1

Index    Columns    Rows

-------  ---------  ------

0          5       6

1          4       7

2          3       4

3          3       6

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

0

Example 2

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

2

Choose a table index (to display):

4

Incorrect table index. Try again.

Choose a table index (to display):

3

Rabbit      Birth year  Favorite treat

--------  ------------  ----------------

Rabbit_1          2022  Carrots

Rabbit_2          2023  Celery

Rabbit_3          2023  Broccoli

Rabbit_4          2024  Cabbage

Rabbit_5          2022  Lettuce

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

0

Example 3

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

3

Choose a table index (to duplicate):

1

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

1

Index    Columns    Rows

-------  ---------  ------

0          5       6

1          4       7

2          3       4

3          3       6

4          4       7

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

2

Choose a table index (to display):

4

Student ID  First Name    Last Name    Grade Code

------------  ------------  -----------  ------------

798154  Brynhildr     Blakeley     N

134789  Felix         Li           N

798951  Paityn        Summers      P

465120  Turnus        Elliot       C

963245  Alysia        Jervis       D

469120  Muhammad      Saad         HD

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

0. Quit.

==================================

0

4. Create table

This menu creates a table from an existing table by selecting some of its columns in a certain order.

It repeatedly asks the user Choose a table index (to create from): until a correct index is input.

It then asks the user Enter the comma-separated indices of the columns to keep:.

Each index must be between 0 and the current number of columns of that table, minus one.

The order of the indices determines the order of the columns of the created table.

The index of the new table is the smallest index that has not previously been assigned to a table.

See example 1.

Assume that the user and test inputs are well-formatted (e.g. 3,1, without spaces) and the set of indices is valid.

5. Delete table

This menu option repeatedly asks the user to select a table by its index (as shown by menu option 1) with Choose a table index (for table deletion):, then deletes the table.

Note that deleting a table does not change the indices of other tables. See example 2.

Examples

User inputs are in bold font below.

Example 1

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

0. Quit.

==================================

4

Choose a table index (to create from):

6

Incorrect table index. Try again.

Choose a table index (to create from):

1

Enter the comma-separated indices of the columns to keep:

3,1

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

0. Quit.

==================================

2

Choose a table index (to display):

4

Grade Code    First Name

------------  ------------

N             Brynhildr

N             Felix

P             Paityn

C             Turnus

D             Alysia

HD            Muhammad

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

0. Quit.

==================================

0

Example 2

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

0. Quit.

==================================

5

Choose a table index (for table deletion):

2

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

0. Quit.

==================================

1

Index    Columns    Rows

-------  ---------  ------

0          5       6

1          4       7

3          3       6

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

0. Quit.

==================================

2

Choose a table index (to display):

2

Incorrect table index. Try again.

Choose a table index (to display):

1

Student ID  First Name    Last Name    Grade Code

------------  ------------  -----------  ------------

798154  Brynhildr     Blakeley     N

134789  Felix         Li           N

798951  Paityn        Summers      P

465120  Turnus        Elliot       C

963245  Alysia        Jervis       D

469120  Muhammad      Saad         HD

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

0. Quit.

==================================

5

Choose a table index (for table deletion):

2

Incorrect table index. Try again.

Choose a table index (for table deletion):

3

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

0. Quit.

==================================

0

6. Delete column

This menu option allows the user to delete a column from a table.

Similar to other menu options, the program repeatedly prints Choose a table index (for column deletion): until a correct index is input.

Then the program prints Enter the index of the column to delete:.

The user then inputs one column index, between 0 and the current number of columns of that table, minus one.

That column is then deleted, which is for example reflected in menu option 1 and 2.

See example 1.

Assume that the column index is valid.

Deleting a column in a table does not affect any other table.

7. Restore table

This menu option allows a user to restore a table that has been deleted via menu option 5.

It prompts Choose a table index (for restoration): and reads a table index from the user.

If the table index is invalid (either the table exists and has not been deleted, or has never existed), then the program prints Incorrect table index. Try again., and iterates until a valid index has been input.

The deleted table is then restored with the index it had prior to deletion.

Assume that this menu option is only used if a table has been deleted.

Examples

User inputs are in bold font below.

Example 1

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

1

Index    Columns    Rows

-------  ---------  ------

0          5       6

1          4       7

2          3       4

3          3       6

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

6

Choose a table index (for column deletion):

6

Incorrect table index. Try again.

Choose a table index (for column deletion):

2

Enter the index of the column to delete:

1

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

1

Index    Columns    Rows

-------  ---------  ------

0          5       6

1          4       7

2          2       4

3          3       6

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

2

Choose a table index (to display):

2

First Name    Rabbit

------------  --------

Brynhildr     Rabbit_1

Turnus        Rabbit_2

Jamaluddin    Rabbit_5

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

0

Example 2

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

5

Choose a table index (for table deletion):

2

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

7

Choose a table index (for restoration):

1

Incorrect table index. Try again.

Choose a table index (for restoration):

2

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

1

Index    Columns    Rows

-------  ---------  ------

0          5       6

1          4       7

2          3       4

3          3       6

==================================

Enter your choice:

1. List tables.

2. Display table.

3. Duplicate table.

4. Create table.

5. Delete table.

6. Delete column.

7. Restore table.

0. Quit.

==================================

0