Solved Stage 1 — KeyError when mass_kg is missing EMEmmaCodesOP 12 Sep, 10:38 edited My negative mass check crashes for the record without mass.
MAMateoG12 Sep, 16:38 Solutionreplies: 2Check that the key exists before comparing. Combine the two conditions with and — Python stops evaluating at the first False, so the comparison never runs when the key is missing.
JAJackStack12 Sep, 23:20Returning a list of problems instead of stopping at the first is a great UX pattern. Users can fix everything in one go.
Comments 4
Join the discussion CommentAlready have an account? Log in
Check that the key exists before comparing. Combine the two conditions with
and— Python stops evaluating at the first False, so the comparison never runs when the key is missing.Short-circuit evaluation to the rescue.
Like good form validation on websites.
Returning a list of problems instead of stopping at the first is a great UX pattern. Users can fix everything in one go.