Project Tree

Using the awdur:project-tree directive, you can insert an interactive view allowing you to browse the files included in a project.

math
fib.py

def fib(n):
    if n == 0 or n == 1:
        return n
    return fib(n-1) + fib(n - 2)

nums = [str(fib(n)) for n in range(1, 11)]
print(f"The first 10 Fibonacci numbers are: {', '.join(nums)}")
square.py

def square(n):
    return n * n

nums = [str(square(n)) for n in range(1,11)]
print(f"The first 10 square numbers are: {', '.join(nums)}")
shapes
triangle.py

def perimeter(a, b, c):
    return a + b + c

def area(a, b, c):
    return 0.5 * a * b

a, b, c = 3, 4, 5
P = perimeter(a, b, c)
A = area(a, b, c)

print(f"A triangle with sides {a=}, {b=}, {c=} has")
print(f"- Perimeter, {P=}")
print(f"- Area, {A=}")
hello.py

print("Hello, World!")

For details on the code itself, see below

Hello World

The code below is a valid "Hello, World!" application in Python.

hello.py
print("Hello, World!")

Triangles

Say we were writing a program involving triangles, we might first write a function to calculate the perimeter

shapes/triangle.py
def perimeter(a, b, c):
    return a + b + c

We might then also write a function to calculate the area

shapes/triangle.py
def area(a, b, c):
    return 0.5 * a * b

Since this is a documentation file, we can make clear the assumptions the above function makes.

Finally, we may bring this all together into a simple program

shapes/triangle.py
a, b, c = 3, 4, 5
P = perimeter(a, b, c)
A = area(a, b, c)

print(f"A triangle with sides {a=}, {b=}, {c=} has")
print(f"- Perimeter, {P=}")
print(f"- Area, {A=}")

Fibbonacci

Below is a function to calculate the nth Fibonacci number

math/fib.py
def fib(n):
    if n == 0 or n == 1:
        return n
    return fib(n-1) + fib(n - 2)

Which we can then use to print the first 10 Fibonacci numbers

math/fib.py
nums = [str(fib(n)) for n in range(1, 11)]
print(f"The first 10 Fibonacci numbers are: {', '.join(nums)}")

Square Numbers

Here is a function for calculating the square of a number

math/square.py
def square(n):
    return n * n

Which we can then use to print the first 10 square numbers

math/square.py
nums = [str(square(n)) for n in range(1,11)]
print(f"The first 10 square numbers are: {', '.join(nums)}")