Our Python book, starting on page 74, introduces the Exclusive Network program. For this project, we are going to make two of our own versions of that program.
1. Start by creating a new module that contains the program exclusive_network from the book. That program handles a network with five exclusive members. But you want your own exclusive circle to be allowed in. So change the code to allow 5 – 10 users you have chosen. Give each of them some appropriate welcome message.
2. Convert your code to a callable function (with no arguments) named canned_network.
3. Call your function to make sure that it works as you expect.
Real programs like this don’t embed their data in the code. Instead, there is some appropriate data structure that contains the data. Then a simpler program runs by using the data as necessary. We have written a function data_network that does this. Click here to see it. (I have posted it as a .txt file so you will have no problem reading it. You will want to save it as a .py file.)
1. Add this new function to your module. Now change the data to match the data that you created in Part I.
2. Call your function to make sure it works correctly.
These first two functions assign a security level but they don’t do anything with it. Now we’ll change that.
1. Add code to data_network so that, whenever a successful login occurs, the user gets a second line of output. This second line should say something about his/her security level and what it means. To do this, you should write new code that will replace the pass statement that is there now. Your new code should test for security level and then print an appropriate message. You want to do it this way, rather than doing it in the middle of the earlier for statement because, in a more realistic setting, there might be hundreds of users with the same security level. You only want to write each of the security messages once. Hint: use if/elif.
Here’s an example of what happened when I ran my version of this program:
Exclusive Computer Network
Username: George Washington
Password: cherry tree
Security level 5: You have wizard privileges. Congratulations.
Exclusive Computer Network
Username: John Tyler
Security level 2: I suppose it's better than the jailbirds.
1. Modify data_network so that, if login is unsuccessful, it allows additional attempts.
2. Modify data_network so that, instead of specifying all of the necessary values in the program, it reads them from a file (much more like the way real programs do). We will be doing file input for our next program. But if you’d like to jump ahead, you can use that technique here as well. If you want to do this, take a look at the description of our next project: Programming Project 4: Trivia Game. There you’ll see what sections in the book you should read to learn about file input.
Turning in Your Project
Use the turnin system to submit a single module that contains the two functions, canned_network and data_network (your final version, the one from Part III).