Code Toolkit: Python, Fall 2020

Week 13 — Homework assignment

due: Tues, December 8, 8pm

Note that this was not actually assigned as we used this class session for review rather than working through the lesson plan for this week. Consider this an optional / extra credit assignment.

  1. Review the class notes for this week.

  2. [Python] Create a kind of web counter that prompts the user for their name, and tells them how many times they have visited your site.

    Refer back to the homework from last week. Create an HTML page with a form that includes only one field, asking for the user's name.

    Again create a server.py file that:

    • gets the user's name from the HTTP request,
    • and tries to retrieve this username as a key from a SQLite dictionary database.
    • if the key is not already in the dictionary (remember that you can use not in), add the key with a value of 1;
    • Otherwise (if the username key is in the database), increase the value by 1, and set it back as a the value for that key.

    As with last week, return a response. This time, simply tell the user something to the effect of:

    Hi Rory. You have visited this page 42 times.
    

  3. I hope that after mastering these principles, you should be able to refer back to week 11 to adapt this for your final project.