main.py: 16 points
In this step we’ll set up main.py
. This file will be the entrypoint to our sorting visualization: it’s the file users should run when they want to use our program, and it will give them access to all of the functionality we want to make available.
Over the course of this semester, you’ve practiced implementing a number of menus already, so we leave it to you to decide the details of your implementation. However choose to write this program is up to you, as long as it satisfies the four requirements below.
When the user runs python3 main.py
, our program should present them with a menu of available options and prompt them for the input we need to proceed.
At the moment we can only produce a text-based visualization with one of two sorting algorithms, so the menu will be fairly simple. To start, your program should produce the following output:
Welcome to the sorting algorithm visualization tool!
The following algorithms are available:
1: Selection Sort
2: Insertion Sort
Please enter your selection:
So far we only have two algorithms to choose from but we will add more in later sections.
Make sure your program does not crash if the user does something weird. If the user enters an invalid choice, display a message saying that it was invalid and prompt them to try again. For example, if the user enters “b” your program might print:
'b' is not a valid selection. Please try again.
It should then show the menu of available options again. An invalid choice should not cause the program to exit.
To run our visualization, we need some data to sort. To satisfy this requirement, have your program create an instance of the DataSet Class object with 15 random values ranging between 0 and 15.
Using relatively small values helps to avoid running out of space in the terminal. In later sections, after we’ve implemented the graphical visualization, we can come back and give the user the option to choose that instead.
Once you have processed the user’s input, run the visualization corresponding to their selection on the DataSet object you created.
As noted in the requirements above, we will come back to update this part of the program in subsequent sections to make new features available to the user as we complete them. To make life better for your future self, try to write your code in such a way that makes it easy to extend with new features that may come later. For example, you should consider what needs to be done to add new options to your menu, including the ability to choose additional sorting algorithms or select a different class for generating and displaying data.