• JUPYTER
  • FAQ
  • View as Code
  • Python 3 (ipykernel) Kernel
  • View on GitHub
  • Execute on Binder
  • Download Notebook
  1. learn-python3
  2. notebooks
  3. beginner
  4. exercises

1. Identifying bugs in code¶

The following stripped_reversed_lowercase function contains at least one bug. You can see this by running the code in the cell below which tests the functionality of the stripped_reversed_lowercase function.

Set trace at the beginning of stripped_reversed_lowercase and use debugger to solve the bug(s). Execute the code line by line and print variables used in the function to understand what's going wrong.

In [ ]:
def stripped_reversed_lowercase(original):
    # Set a breakpoint here and start debugging
    # from IPython.core.debugger import Pdb; Pdb().set_trace()
    stripped = original.lstrip()
    reversed = " ".join(reversed(stripped))
    reversed.lower()
    return reversed
In [ ]:
# Let's verify it works
original = " \n Original String "
result = stripped_reversed_lowercase(original)
assert result == "gnirts lanigiro"

This website does not host notebooks, it only renders notebooks available on other websites.

Delivered by Fastly, Rendered by OVHcloud

nbviewer GitHub repository.

nbviewer version: 8b013f7

nbconvert version: 7.2.3

Rendered (Tue, 10 Jun 2025 07:09:31 UTC)