Projects

10 Useful Python Scripts for Beginners

Useful scripts solve small, concrete problems. Start with one of these: count words, clean names, check duplicates, total expenses, filter CSV rows, summarize logs, validate filenames, parse JSON, organize a reading list, or generate a simple report.

Step by step

  1. Choose a task with a small, known input.
  2. Make the output visible before writing files.
  3. Add a test for an empty input.
  4. Document how to run the script and what it does not do.

Run this example

Use Python 3. Copy the code into a file or interactive Python environment.

tasks = ["backup", "email", "backup", "report"]
unique = sorted(set(tasks))
print("Unique tasks:", ", ".join(unique))
print("Count:", len(unique))

Expected output

Unique tasks: backup, email, report
Count: 3

Common issue

A `set` removes duplicates but does not preserve the original sequence; use `dict.fromkeys(tasks)` when order matters.

Try it yourself

Implement a word counter using `split()` and test it on an empty string.

Ten complete, runnable scripts

Run each block independently in Python 3. These examples use the standard library, sample data, and no external services. Save one block in a .py file, predict its output, run it, and then adapt the input.

1. Count words

split handles whitespace. This counts whitespace-separated tokens, not linguistic words.

text = "Python makes small tasks easier"
print(f"Words: {len(text.split())}")

Expected output

Words: 5

2. Clean names

Strip outside spaces and normalize case for consistent comparison.

names = [" Ada ", "BOB"]
print(", ".join(name.strip().title() for name in names))

Expected output

Ada, Bob

3. Remove duplicates in order

Dictionary keys preserve insertion order; repeated values appear once.

tasks = ["backup", "email", "backup"]
print(", ".join(dict.fromkeys(tasks)))

Expected output

backup, email

4. Total expenses

Decimal represents these decimal amounts exactly; construct it from strings.

from decimal import Decimal
expenses = [Decimal("12.50"), Decimal("3.25")]
print(f"Total: ${sum(expenses):.2f}")

Expected output

Total: $15.75

5. Filter CSV rows

DictReader interprets headers and quoting; convert numeric fields before comparing.

import csv
from io import StringIO
rows = csv.DictReader(StringIO("name,units\nPen,2\nNotebook,5\n"))
for row in rows:
    if int(row["units"]) >= 3:
        print(row['name'])

Expected output

Notebook

6. Summarize log levels

Counter counts repeated labels. Explicit keys keep the report order predictable.

from collections import Counter
counts = Counter(["INFO", "ERROR", "INFO", "WARNING"])
for level in ["INFO", "WARNING", "ERROR"]:
    print(f"{level}: {counts[level]}")

Expected output

INFO: 2
WARNING: 1
ERROR: 1

7. Check a filename convention

This checks a chosen naming convention, not every operating-system filename rule.

import re
names = ["report-01.csv", "Report final.csv"]
for name in names:
    valid = bool(re.fullmatch(r"[a-z0-9-]+[.]csv", name))
    print(f"{name}: {valid}")

Expected output

report-01.csv: True
Report final.csv: False

8. Read a JSON record

loads parses JSON text. Required keys and types still need validation in a real application.

import json
record = json.loads('{"name": "Ada", "lessons": 4}')
print(f"{record['name']}: {record['lessons']} lessons")

Expected output

Ada: 4 lessons

9. Sort a reading list

Sorting by casefold gives a case-insensitive order without changing the displayed titles.

titles = ["Python Basics", "automation", "CSV Guide"]
for title in sorted(titles, key=str.casefold):
    print(title)

Expected output

automation
CSV Guide
Python Basics

10. Generate a progress report

Combine a condition and count into a short reproducible report.

completed = [True, False, True, True]
count = sum(completed)
print(f"Completed: {count}/{len(completed)}")
print(f"Progress: {count / len(completed):.0%}")

Expected output

Completed: 3/4
Progress: 75%

Make a script useful on real data

Replace sample data only after documenting the expected shape. Validate missing columns, empty inputs, and malformed numbers. Keep calculations in functions, and add file operations separately. The progress script needs a guard before division if the list can be empty.

Exercises with checkable outcomes

  1. Set the word-counter input to an empty string: expect Words: 0.
  2. Add another $4.25 expense: expect Total: $20.00.
  3. Add Pen,4 to the CSV: expect Notebook followed by Pen.
  4. Implement an empty progress report that prints No tasks instead of dividing by zero.

Common failures

JSON requires double quotes for keys and strings. CSV numbers arrive as text. Names that differ only in case remain distinct unless you normalize them before deduplication. A regular expression checks only the convention you wrote; it is not a universal security or filename validator.

Keep learning

Read the relevant documentation · Free foundational resources

Related guides: How to Write Your First Python Automation Script and How to Read and Write CSV Files With Python.

Interested in applying these skills to a product? Explore the optional Python to Profit course. It focuses on product and business building, not replacing foundational Python study.