ProjectBeginner·45 min·0/52 done

Project: Review Sentiment Checker

Your first project. Label product reviews as positive, negative or neutral using only strings, lists, dicts and loops, then put it on GitHub.

Why it matters: Sentiment analysis is a classic AI task. Build the simple rule-based version first, and the machine learning version in Module 3 will make sense.

Step 1

What you will build

A program that reads five course reviews and prints a label for each, plus a summary:

  • positive when a review has more good words than bad words
  • negative when it has more bad words
  • neutral when they are equal

You only need Module 1: strings, lists, dicts, for and if. Build it in the editor below, then run it on your laptop and publish it on GitHub.

Step 2

Clean each review

Computers compare text exactly, so "Great" and "great" are different words. Lowercase everything first.

Punctuation sticks to words ("course,"), so replace , . and ! with spaces before you split().

Tiny example

Lowercase, remove punctuation, split into words.

review = "Great course, loved it!"
clean = review.lower().replace(",", " ").replace("!", " ")
words = clean.split()
print(words)

Step 3

Count good and bad words

Keep a counter for good words and one for bad words. Loop over the words and add 1 when a word is in the matching list.

Tiny example

Check each word against a list with in.

positive_words = ["good", "great", "loved"]
words = ["great", "course", "loved", "it"]
good = 0
for word in words:
    if word in positive_words:
        good += 1
print("good words:", good)

Step 4

Decide the label

Compare the counts with if, elif and else. A review with one good and one bad word, like "Loved the projects but the audio was bad", is neutral.

Then add the label to the labels list and count it in the summary dict with summary[label] += 1.

Tiny example

Compare the two counts.

good, bad = 1, 1
if good > bad:
    label = "positive"
elif bad > good:
    label = "negative"
else:
    label = "neutral"
print(label)

Build it here · answer checked automatically

Build the project

Fill in the loop. For each review, put its label in labels (in the same order as reviews) and add 1 to the matching count in summary. Print each label next to its review.

Edit the code, then press Run & check. Passing it marks this project done.

python console

Project

~/lesson.py

Ctrl+Enter

console output

ready

$ waiting for Run...

On your laptop

Run the real thing on your computer

Running code on your own computer and publishing it on GitHub is what employers expect. Do it once now, and every later project is easy.

  1. 1

    Install Python from python.org. On Windows, tick Add python.exe to PATH in the installer. Check it in a terminal (Mac and Linux: python3 --version):

    python --version
  2. 2

    Install VS Code (free) and its Python extension. Make a folder called sentiment-checker and open it in VS Code.

  3. 3

    Save the three files below into that folder (use the Download buttons). Edit the What I learned part of the README in your own words.

  4. 4

    Open the terminal in VS Code with Terminal > New Terminal.

sentiment_checker.py

"""Review Sentiment Checker: label reviews as positive, negative or neutral."""

positive_words = ["good", "great", "love", "loved", "excellent", "helpful", "clear"]
negative_words = ["bad", "boring", "confusing", "slow", "hate", "poor", "waste"]

reviews = [
    "Great course, the examples were clear and helpful!",
    "Too slow and confusing. A waste of time.",
    "The videos are long.",
    "Loved the projects but the audio was bad.",
    "Excellent trainer, good notes, I love it",
]

labels = []
summary = {"positive": 0, "negative": 0, "neutral": 0}

for review in reviews:
    clean = review.lower().replace(",", " ").replace(".", " ").replace("!", " ")
    words = clean.split()

    good = 0
    bad = 0
    for word in words:
        if word in positive_words:
            good += 1
        elif word in negative_words:
            bad += 1

    if good > bad:
        label = "positive"
    elif bad > good:
        label = "negative"
    else:
        label = "neutral"

    labels.append(label)
    summary[label] += 1
    print(f"{label:>8} | {review}")

print()
print("Summary:", summary)

README.md

# Review Sentiment Checker

A small Python program that labels product reviews as positive, negative or neutral
by counting positive and negative words.

## How to run

    python sentiment_checker.py

## Example output

    positive | Great course, the examples were clear and helpful!
    negative | Too slow and confusing. A waste of time.
     neutral | The videos are long.

## What I learned

- Cleaning text with lower(), replace() and split()
- Using lists, dictionaries, loops and if / elif / else together
- Why simple word rules miss sentences like "not good", and why ML models help

## Next ideas

- Read the reviews from a text file
- Handle "not good" and "not bad"

.gitignore

__pycache__/
.venv/

Run it from the same folder:

python sentiment_checker.py

You should see something like:

positive | Great course, the examples were clear and helpful!
negative | Too slow and confusing. A waste of time.
 neutral | The videos are long.
 neutral | Loved the projects but the audio was bad.
positive | Excellent trainer, good notes, I love it

Summary: {'positive': 2, 'negative': 1, 'neutral': 2}

Show it to recruiters

Put it on GitHub

  1. 1

    Create a free account at github.com if you do not have one yet.

  2. 2

    Click + (top right), then New repository. Name it sentiment-checker, choose Public, and click Create repository.

  3. 3

    Easiest way: on the new repository page, click uploading an existing file, drag in sentiment_checker.py, README.md, .gitignore, and click Commit changes. Done.

  4. 4

    The way companies work: install Git from git-scm.com, open a terminal in your project folder, and run these. Replace YOUR-USERNAME with your GitHub username. The two git config lines are needed only once per computer. The first push asks you to sign in: on Windows a browser window opens. On Mac or Linux, GitHub does not accept your account password here, so use a personal access token as the password, or publish with GitHub Desktop instead.

    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    git init
    git add .
    git commit -m "First version of sentiment-checker"
    git branch -M main
    git remote add origin https://github.com/YOUR-USERNAME/sentiment-checker.git
    git push -u origin main
  5. 5

    Put the repository link on your resume and LinkedIn under Projects, with one line on what it does and one on what you learned. Recruiters open these.

Takeaways

  • 1Clean text before you compare it: lowercase and remove punctuation.
  • 2Lists, dicts and loops are enough to build a useful first program.
  • 3Rules break on sentences like 'not good'. That is why AI teams train models.