Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    PyPython

    Getting started

    • Your first Python program
    • Variables and types
    • Numbers and operators
    • Type conversion and input

    Strings

    • Strings and f-strings
    • String indexing and slicing
    • Cleaning and splitting strings

    Control flow

    • Conditions: if, elif and else
    • Loops: for and while
    • Loop control and nesting

    Functions

    • Functions with def
    • Parameters and scope

    Collections

    • Lists
    • Dictionaries
    • Tuples and sets
    • Comprehensions, enumerate and zip

    Errors, files and libraries

    • Handling exceptions
    • Modules and the standard library
    • Reading and writing files
    • Exchanging data with JSON

    Objects and lazy iteration

    • Classes and objects
    • Inheritance and composition
    • Iterators and generators

    Testing and project

    • Testing and project setup
    • Project: a grade report
    Python

    Testing and project · Lesson 24 of 25

    Testing and project setup

    Normal cases, boundaries, expected errors and an isolated environment.

    8 minutes1 games

    Split your program into small functions and test known inputs: a normal case, a boundary and invalid input. unittest is in the standard library. Locally create an environment with python -m venv .venv and install dependencies with python -m pip after activating it. These terminal commands do not belong in this Python editor.

    Python
    import unittest
    
    def is_even(n):
        return n % 2 == 0
    
    class TestEven(unittest.TestCase):
        def test_even(self):
            self.assertTrue(is_even(4))
    
        def test_zero(self):
            self.assertTrue(is_even(0))
    
        def test_odd(self):
            self.assertFalse(is_even(3))
    
    result = unittest.TestResult()
    unittest.defaultTestLoader.loadTestsFromTestCase(TestEven).run(result)
    print(result.testsRun, result.wasSuccessful())
    ToolUse

    حالة عادية / Normal

    An even number: 4

    حد فاصل / Boundary

    Zero

    حالة عكسية / Opposite

    An odd number: 3

    Important

    assert is useful for development assumptions, but not user-input validation; Python may remove assertions under -O.

    Interview question

    Does one passing test prove all inputs work?

    Exercise

    Implement safe_divide: return None for a zero divisor, otherwise divide. Print both cases.

    Expected output:
    3.0
    None
    Python

    Learn more from

    • Python documentationdocs.python.org
    • Real Python: further readingrealpython.com

    Played 0 of 1 games

    Sign in to save your progress and earn XP.

    PreviousIterators and generatorsNextProject: a grade report
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.