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

1. if-elif-else¶

Fill missing pieces (____) of the following code such that prints make sense.

In [ ]:
name = "John Doe"
In [ ]:
if ____:
    print(f'Name "{name}" is more than 20 chars long')
    length_description = "long"
elif ____:
    print(f'Name "{name}" is more than 15 chars long')
    length_description = "semi long"
elif ____:
    print(f'Name "{name}" is more than 10 chars long')
    length_description = "semi long"
elif ____:
    print(f'Name "{name}" is 8, 9 or 10 chars long')
    length_description = "semi short"
else:
    print(f'Name "{name}" is a short name')
    length_description = "short"
In [ ]:
assert length_description == "semi short"

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:19 UTC)