Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert a Jupyter notebook to HTML format.
Data Analysis Python
import nbconvert html_exporter = nbconvert.[1]() output = html_exporter.from_filename('report.ipynb')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using PDFExporter instead of HTMLExporter.
Confusing MarkdownExporter with HTMLExporter.
✗ Incorrect
The HTMLExporter class converts notebooks to HTML format.
2fill in blank
mediumComplete the code to save the HTML output to a file.
Data Analysis Python
with open('report.html', [1]) as f: f.write(output[0])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' mode which is for reading.
Using 'a' mode which appends instead of overwriting.
✗ Incorrect
Use 'w' mode to write text to a new file or overwrite an existing file.
3fill in blank
hardFix the error in the code to convert a notebook to PDF using nbconvert.
Data Analysis Python
import nbconvert pdf_exporter = nbconvert.[1]() output = pdf_exporter.from_filename('report.ipynb')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using HTMLExporter when PDF output is needed.
Using SlidesExporter which is for slide presentations.
✗ Incorrect
To convert to PDF, use PDFExporter from nbconvert.
4fill in blank
hardFill both blanks to create a PDF file from notebook content.
Data Analysis Python
with open('report.pdf', [1]) as f: f.write(output[[2]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Opening the file in text mode 'w' for PDF output.
Writing the second element of output which is resources/metadata, not PDF data.
✗ Incorrect
PDF files are binary, so open the file in 'wb' mode and write the first element of output which contains the PDF data.
5fill in blank
hardFill all three blanks to convert a notebook to HTML and save it with nbconvert.
Data Analysis Python
from nbconvert import [1] exporter = [2]() body, resources = exporter.from_filename('analysis.ipynb') with open('analysis.html', [3]) as f: f.write(body)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing PDFExporter when HTML output is needed.
Opening the file in binary mode for HTML output.
✗ Incorrect
Import HTMLExporter from nbconvert, create an exporter instance, and write the HTML body to a file opened in write mode.