Command Palette

Search for a command to run...

Hectal
Phase 6: Modules, Packages and Projects
Python · Exercise 1 of 5Next
Intermediate

Classify a requirements line

Write a function pin_status(line). Its input line is one line of a requirements.txt file, written as text, for example "requests==2.32.3".

Return "pinned" if the line contains ==, "range" if it contains any of >, < or ~ (and no ==), and "unpinned" otherwise.

Then print pin_status("requests==2.32.3").

What Check tests

  1. pin_status("requests==2.32.3") is "pinned"
  2. pin_status("numpy>=1.26,<3") is "range"
  3. pin_status("rich~=13.7") is "range"
  4. pin_status("pandas") is "unpinned"
  5. Spaces around == still count as pinned
  6. pin_status("flask<3") is "range"
  7. The program prints pinned

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.