Recorded demo · Programming or code (read, not run)
Python: word frequency function
Graded by GradeHomeworkOnline on fictional student work. Nothing here is live, and nothing you do changes it. Every grade here is still a proposal: none has been approved.
Step 1The assignment
Write a Python function word_counts(text) that returns a dictionary mapping each word (lower case, punctuation removed) to the number of times it appears. Include a docstring and handle an empty string.
Step 2The rubric: 3 criteria, 10 points
| Criterion | Points |
|---|---|
| CorrectnessReturns correct counts, lower-cases words and removes punctuation. | 5 |
| Edge casesHandles an empty string (returns an empty dictionary) and repeated spaces. | 3 |
| ReadabilityClear names, a docstring, and simple structure. | 2 |
Step 3The class: 4 fictional students
Sample-student-01.py
import string def word_counts(text): """Return a dict mapping each lower-case word in text to its count.""" cleaned = text.lower().translate(str.maketrans('', '', string.punctuation)) counts = {} for word in cleaned.split(): counts[word] = counts.get(word, 0) + 1 return countsSample-student-02.py
def word_counts(text): d = {} for w in text.split(' '): if w in d: d[w] += 1 else: d[w] = 1 return dSample-student-03.py
from collections import Counter import re def word_counts(text): """Count words, ignoring case and punctuation.""" words = re.findall(r"[a-z']+", text.lower()) return dict(Counter(words))Sample-student-04.py
def word_counts(text): # count words words = text.lower().split() result = {} for word in words: word = word.strip('.,!?') result[word] = words.count(word) return result
Step 4The settings
- Grading level
- Fast
- each submission graded once
- Strictness
- Balanced
- Feedback
- Standard
Step 5Checked before grading: 8 requirements read from the rubric
Before anything is graded, the rubric's own words are turned into requirements, each with the words it came from. The instructor checks them, then locks the job.
Correctness (3)
- Returns correct word counts. — “Returns correct counts”
- Lower-cases words. — “lower-cases words”
- Removes punctuation. — “removes punctuation”
Edge cases (2)
- Returns an empty dictionary for an empty string. — “Handles an empty string (returns an empty dictionary)”
- Handles repeated spaces. — “Handles an empty string (returns an empty dictionary) and repeated spaces.”
Readability (3)
- Uses clear names. — “Clear names”
- Includes a docstring. — “a docstring”
- Uses a simple structure. — “simple structure”
Grading results
Run state: loading
Submissions
0 shown
0 of 0 shown.
| Submission | Status | Grade | Review | Evaluations | Actions |
|---|
Approve this run
Not approved
These grades and feedback were proposed by AI and can be wrong. Review each one, and correct any you disagree with, before you approve them or give them to students.
Approval is your explicit acceptance of these grades. Looking at results or closing this page does not approve them. After approval, grades in this run can no longer be corrected.
Next demo: Persuasive essay: free public transit
Open it