Problem Set 6: Sentimental

tl;dr

  1. Watch Week 8’s lecture (and Week 6’s and Week 7’s, if you haven’t already).

  2. Port some programs from C to Python.

  3. Analyze some sentiments.

  4. Submit a form.

Help

For help with Weeks 6 – 8 and Problem Set 6:

  • Attend David’s walkthrough on Mon 10/24, 1pm – 2:30pm, in Sanders Theatre.

  • Watch David’s walkthrough (of Sentiments) herein (coming Mon 10/24 eve).

  • Attend your TF’s section (or another if you have a conflict).

  • Post questions and search answers in CS50 Discuss.

  • Attend individual TFs' and CAs' office hours at HSA.

  • Attend course-wide office hours.

Academic Honesty

Do keep in mind the course’s policy on academic honesty, particularly its "regret clause."

Getting Started

update50
mkdir ~/workspace/pset6/
cd ~/workspace/pset6/

Problems

All code that you write should be consistent with Style Guide for Python Code, otherwise known as PEP 8.

  1. Implement either of the below exactly as specified but in Python:

    • Mario, less comfortable, in a file called mario.py in pset6/.

    • Mario, more comfortable, in a file called mario.py in pset6/.

  2. Implement either of the below exactly as specified but in Python:

    • Greedy, less comfortable, in a file called greedy.py in pset6/.

    • Credit, more comfortable, in a file called credit.py in pset6/.

  3. Implement any (one) of the below exactly as specified but in Python:

    • Caesar, less comfortable, in a file called caesar.py in pset6/.

    • Vigenère, less comfortable, in a file called vigenere.py in pset6/.

    • Crack, more comfortable, in a file called crack.py in pset6/.

  4. Implement Sentiments in pset6/sentiments/.

No check50 for these!

Hints

  • Be sure to use Python 3, not Python 2.

  • If a program is in a file called, say, foo.py, you can run that program with python foo.py.

  • For Mario, Greedy, Credit, Caesar, Vigenère, and Crack, it is reasonable to look at your own implementations thereof in C and others' implementations thereof in C, including the staff’s implementations thereof (and postmortems) in C. It is not reasonable to look at others' implementations of the same in Python. It is not reasonable to look at others' implementations of Sentiments.

  • Consider this problem set an opportunity not only to port your own prior work from C to Python but to improve upon your earlier designs using lessons learned since!

  • When porting code from C to Python in CS50 IDE, you might want to select View > Layout > Horizontal Split so that you can see both side by side.

  • Insofar as a goal of this problem set is to teach you how to teach yourself a new language, keep in mind that these acts are not only reasonable, per the syllabus, but encouraged toward that end:

    • Incorporating a few lines of code that you find online or elsewhere into your own code, provided that those lines are not themselves solutions to assigned problems and that you cite the lines' origins.

    • Turning to the web or elsewhere for instruction beyond the course’s own, for references, and for solutions to technical difficulties, but not for outright solutions to problem set’s problems or your own final project.

  • You’re welcome to use the CS50 Library for Python, which includes get_float, get_int, and get_string. Just remember to include

    import cs50

    atop your code. Or you can use input and validate users' input yourself.

  • You might find chr and/or ord of help.

  • You might find these references of interest:

Walkthrough

FAQs

AttributeError: 'module' object has no attribute get_

If seeing this error (for cs50.get_char, cs50.get_float, cs50.get_int, or cs50.get_string), try executing the below (which fixes a bug in an earlier version of the CS50 Library for Python):

sudo chmod -R a+rX /usr/lib/python2.7/dist-packages/cs50
sudo chmod -R a+rX /usr/lib/python3/dist-packages/cs50

ImportError: No module named 'sqlalchemy'

If seeing this error, execute

pip install --user sqlalchemy

to resolve!

How to Submit

Step 1 of 2

update50
cd ~/workspace/pset6/
submit50 pset6

Step 2 of 2

This was Problem Set 6.