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
pin_status("requests==2.32.3")is "pinned"pin_status("numpy>=1.26,<3")is "range"pin_status("rich~=13.7")is "range"pin_status("pandas")is "unpinned"- Spaces around
==still count as pinned pin_status("flask<3")is "range"- 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.