Write data to a CSV file

Create a table whose headers are "Name", "Age", and "Email Address". Then add your name, age, and email address as the first data row.

Write the table to a file called user_data.csv. Use a nested list to represent the rows, pathlib.Path for the file path, and the csv module to write the data. Opening a file in write mode replaces its existing contents, so test your function with a disposable file.

Start from the function template in Listing 1.

Listing 1: Function template for writing a header and one user record to CSV.
import csv
from pathlib import Path


def write_user_data(
    file_path: Path,
    name: str,
    age: int,
    email_address: str,
) -> None:
    rows = [["Name", "Age", "Email Address"], [name, age, email_address]]

    # Open file_path and write every row in rows.
    raise NotImplementedError