Recap: Validate a Batch
Lesson 31 of 48 in Coddy's Python for GDScript Developers course.
Challenge
BeginnerRead a nonnegative integer count n, followed by exactly n raw record lines. A valid record has exactly two comma-separated fields: a name and a quantity. Strip surrounding whitespace from both. The name must be nonempty; internal spaces are allowed. The quantity must convert with int and be between 0 and 100 inclusive. Other records are invalid. For each valid record print name:quantity. For each invalid record print error:position, using its one-based input position. Continue after invalid records. Finally print accepted=A rejected=R total=T, replacing the capital letters with counts and the sum of accepted quantities. Preserve record order; duplicate names remain separate records. Use explicit validation and catch expected conversion errors.
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 GDScript Developers
1From GDScript to Python
Run Your First Python ProgramPrint Is Not printsVar, Const, and BindingsInteger Division DifferencesSimilar Indentation, New ScopeRecap: Rewrite a Receipt4Iteration and Transformations
Ranges and RebindingItems and enumerateWhile and Early ExitArray Callbacks and KeysRecap: Build a Ranking2Values and Decisions
Null and NoneThe is Keyword Changes MeaningLogical Results and OperandsConditional ExpressionsRecap: Eligibility Rules3Collections and Shared State
Array and List APIsArrays, Vectors, and TuplesDictionary Lookup RulesDuplicate and Shallow CopyRecap: Clean an Inventory6Input, Errors, and Modules
Console Work Outside GodotValidation and ExceptionsScript Resources and ImportsTyped GDScript and AnnotationsRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler