Recap: Clean an Inventory
Lesson 16 of 48 in Coddy's Python for Swift Developers course.
Challenge
BeginnerRead six lines: three scanned item codes, integer stock counts for pen and pad, and a lookup code. Codes are nonempty lowercase ASCII words; counts are nonnegative. Print the sorted list of unique scanned codes in Python list format. Next print a tuple containing the first and last codes in that sorted list. Then print whether the lookup code is a stock key and its count, using 0 if unknown. Only pen and pad are stock keys, regardless of which codes were scanned. Print one result per line.
Print only the requested output, with a newline after each line. Keep the supplied input scaffold. No loops or functions are needed.
Your code goes in main.py. The locked driver.py starts your program and cannot be edited.
Try it yourself
# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module
run_module("main", run_name="__main__")
All lessons in Python for Swift Developers
1From Swift to Python
Run Your First Python ProgramPrinting and Stringslet, var, and RebindingInt Range and DivisionIndentation and Block ScopeRecap: Rewrite a Receipt4Iteration and Transformations
for and Half-Open Rangesenumerated to enumeratewhile and Loop Controlmap, filter, ComprehensionsRecap: Build a Ranking2Values and Decisions
Optionals and NoneEquatable and IdentityBool Conditions and FallbacksBranches and TernariesRecap: Eligibility Rules3Value Types to Shared Objects
Array to listTuples and UnpackingDictionary Lookup and OrderValue Copies and AliasesRecap: Clean an Inventory6Errors and Modules
Input and String Formattingthrows, defer, and withModules and Main GuardsHints and Runtime TypesRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler