KarmSakha
Help

Career Coaching & Personal Development

Technical Skills: Worked Python Tests and SQL Examples

Reviewed: 9 October 2026. This guide retains its historical URL but replaces unsupported “highest-paying” rankings with technical work you can demonstrate. The examples are original, local exercises. They do not establish employer demand, a certification or professional experience.

Choose a skill by the task it helps you perform

Start with an actual responsibility and the evidence it needs. A role may involve transforming records, checking input, testing behaviour, interpreting a query or explaining a change. Learning a tool's name is different from showing how you used it and what remains unchecked.

The menu here covers five connected activities: define an input contract, implement a bounded transformation, test specific cases, interpret a join and explain a revision. It is not a market ranking or a claim that every role requires these tools. Compare the activities with the target posting before choosing your learning task.

Official documentation establishes functionality, not Indian salary bands or hiring growth. Avoid treating a course, model name or cloud certificate as proof that you can perform a particular job responsibility.

Skill one: define the input and expected behaviour

Use this original fictional task: a printed booklet has a page limit and a list of chapter lengths. Calculate how many pages remain after those chapters. The function must reject an invalid type, a negative value or a total exceeding the limit.

The input contract is precise: the limit is a nonnegative integer, excluding Boolean values; chapters is a list of nonnegative integers, also excluding Booleans. The output is a nonnegative integer. There is no document upload, real publication, payment or external service.

For a limit of twenty pages and chapter lengths four, six and three, the total is thirteen and seven pages remain. For a ten-page limit and one ten-page chapter, zero remain. A chapter total of eleven against a limit of ten is an error under this contract; it is not automatically truncated.

Writing the contract first helps you distinguish a programming mistake from an unspecified requirement. If the task later allows decimal lengths or cancellation adjustments, that is a changed contract needing its own decisions.

Skill two: implement the original transformation

This complete Python example uses only the standard library:

import unittest


def remaining_pages(limit, chapters):
    if type(limit) is not int or not isinstance(chapters, list):
        raise TypeError("integer limit and list required")
    if limit < 0:
        raise ValueError("negative limit")
    total = 0
    for pages in chapters:
        if type(pages) is not int:
            raise TypeError("integer chapter length required")
        if pages < 0:
            raise ValueError("negative chapter length")
        total += pages
    if total > limit:
        raise ValueError("page limit exceeded")
    return limit - total


class PageChecks(unittest.TestCase):
    def test_remainder(self):
        self.assertEqual(remaining_pages(20, [4, 6, 3]), 7)

    def test_exact_limit(self):
        self.assertEqual(remaining_pages(10, [10]), 0)

    def test_empty(self):
        self.assertEqual(remaining_pages(0, []), 0)

    def test_over_limit(self):
        with self.assertRaises(ValueError):
            remaining_pages(10, [11])

    def test_boolean(self):
        with self.assertRaises(TypeError):
            remaining_pages(True, [])

    def test_negative_chapter(self):
        with self.assertRaises(ValueError):
            remaining_pages(10, [-1])


if __name__ == "__main__":
    unittest.main()

The code visits each supplied chapter once. With a fixed-cost arithmetic model, that is linear work in the number of chapters; actual integer-operation cost can depend on integer size. It does not modify the input list or save a real document.

The exact displayed example was run during this editorial review: all six tests passed. This is evidence for those cases in the reviewed local execution, not a proof of universal correctness or suitability for a production publishing system.

Skill three: explain what a test establishes

Python's official unittest documentation describes test cases checking a specific response to supplied inputs. Its assertEqual checks an expected value and assertRaises checks a specified exception. The original tests above use those facilities; they do not copy the documentation's tutorial fixture.

The Boolean test matters because this contract excludes True as a page limit. The empty test checks zero against an empty list. Neither proves how the function behaves for every possible object or environment.

Try additional contract cases before claiming broader coverage: a negative limit, a Boolean chapter length and a tuple in place of the required list. State which you ran and what happened. A planned test is not a passed test.

If the brief changes to accept a tuple of chapter lengths, revise the contract and implementation together. The current function requires a list. Do not say it already accepts every iterable merely because a loop is used inside it.

Skill four: interpret matching and unmatched records

PostgreSQL's join tutorial explains combining rows under a matching condition and preserving left-side rows with a left outer join. The following original fixture asks which review contacts match three fictional document sections.

WITH sections(section_id, area) AS (
    VALUES ('S1', 'science'), ('S2', 'arts'), ('S3', 'history')
), contacts(area, reviewer) AS (
    VALUES ('science', 'Mira'), ('science', 'Nalin'),
           ('arts', NULL)
)
SELECT s.section_id, s.area, c.area AS matched_area, c.reviewer
FROM sections AS s
LEFT JOIN contacts AS c ON s.area = c.area
ORDER BY s.section_id, c.reviewer;

The expected result is:

SectionAreaMatched areaReviewer
S1sciencescienceMira
S1sciencescienceNalin
S2artsartsNULL
S3historyNULLNULL

S1 appears twice because two contact rows match. S2 has a matching area but an explicitly missing reviewer. S3 has no contact match. Including matched_area makes those last two situations visible. NULL is not a zero value or proof that no matching row existed.

The displayed query was executed locally with SQLite for this standard SQL fixture and produced these four rows. The documentation cited describes PostgreSQL semantics; this review does not claim a PostgreSQL server execution or that the two database engines are identical in every feature.

Skill five: explain a reviewed change and its limit

Suppose the fictional brief now asks for one row per section. The original query does not satisfy that new requirement for S1. You need a rule for choosing or combining multiple contacts; adding a join does not supply that decision automatically.

A complete change note could say: “The first fixture retains both science contacts and produces four rows for three sections. The revised brief requests one row per section. The contact-selection rule is unresolved, so I have not silently discarded a reviewer. Once that rule is approved, I will revise the query and check duplicate, explicit-NULL and unmatched cases again.”

This demonstrates interpretation and communication alongside syntax. A confidently written query can still answer the wrong question if its expected row count or matching rule is unclear.

Turn practice into inspectable evidence

Keep the task, contract, original data, exact code, observed output and limitations together. A reviewer should be able to reproduce the finite example and understand what you did personally. Do not describe a local exercise as a paid employer project or claim users, performance improvements or production scale that were never measured.

Choose the next learning gap from the role's actual requirements. If a posting requests a tool you have not used, record that gap. A Python example does not establish expertise in every framework, cloud platform or security discipline.

The tech career-choice guide helps compare work activities. The goal-setting guide can help define a bounded output and a review point. Neither supplies a salary ranking or guarantees that an employer accepts a particular exercise.

Questions about technical-skill preparation

Which skill is the highest paid? No verified market ranking is supplied here. Use actual role requirements and defensible compensation evidence when assessing opportunities.

Do six passing tests prove job readiness? No. They establish specified cases for this example, with the limits described above.

Does a left join remove duplicates? No. Multiple matching right-side rows can produce multiple result rows.

Should I learn every technology immediately? Select a relevant task and evidence gap. A long list of tool names is not a substitute for checked work.

Related guides

Ask KarmSakha AI