Learning Target: I can use indentation and whitespace to structure my code.
Python uses indentation to define blocks of code. Proper indentation is crucial for the code to run correctly.
def greet(name):
print(f"Hello, {name}!")
greet("Alice")
Write a function that takes a number and prints whether it's even or odd. Make sure to use proper indentation.
Try it here:
Learning Target: I can write comments to explain my code.
Comments are lines in the code that are ignored by Python but help humans understand the code.
# This is a comment
print("Hello, world!") # This prints a message
Write a small program with at least two comments that explain what each part does.
Try it here:
Learning Target: I can use docstrings to document my functions.
Docstrings are special comments used to describe the purpose of a function or module.
def add(a, b):
"""
This function adds two numbers.
:param a: First number
:param b: Second number
:return: Sum of a and b
"""
return a + b
Write a function with a docstring that explains what the function does and its parameters.
Try it here:
pydoc 📖Learning Target: I can generate documentation using pydoc.
pydoc is a module that automatically generates documentation from docstrings.
# Run this command in the terminal to generate documentation
# python -m pydoc -w mymodule
Create a module with functions that have docstrings. Use pydoc to generate the documentation.
Try it here: