[Tutor] (no subject)
dn
PyTutor at DancesWithMice.info
Sun Oct 18 15:23:24 EDT 2020
On 19/10/2020 00:34, Alan Gauld via Tutor wrote:
> On 18/10/2020 08:58, Aliyan Navaid wrote:
>> I want to write a program which list ALL the errors while entering a user
>> name.
>>
>> (If I use if elif blocks the program will end at the first error it
>> catches)
>
> You have just answered your own question.
> Stop using elif clauses. Just use if.
>
> hasErrors = False
> if characters < 3:
> print(“Username too short”)
> hasErrors = True
> if characters > 50:
> print(“Username too long”)
> hasErrors = Trueif special_characters:
> print(“Special characters not allowed”)
> hasErrors = True
> if not hasErrors:
> print(“Username is valid”)
>
> if hasErrors: # Now do something to recover!
>
>
> But it must be said that its an unusual strategy.
> Most programs detect the first error and stop.
There is an advert on (local) TV, mocking the situation where I'd prefer
that the above/usual case not apply:
Two 'wild west' cowboys are apparently being chased, and the bullets are
flying. They reach what they think will be the safety of the barricaded
farm-house and desperately demand to be allowed to enter. "What's the
password?" comes back. They guess. "It has a number in it" is the
unsympathetic response. Next time around, there's some other
requirement. All the while the bullets are flying...
Apparently, that is the time one takes a break to eat a Kit-Kat (a
chocolate bar - with the advertising jingle "have a break, have a Kit-Kat).
How many times have I been asked to select a password, and some wise-guy
at the web-site has decided that (s)he will enforce the use of "strong
passwords"? (for some definition of "strong") Yet, (s)he doesn't think
to communicate all of these requirements up-front - minimum length, must
have at least one letter/digit, must include a "special character", must
be able to shoot coders who fail to communicate...
Per the OP's use-case, listing all* of my (supposed) transgressions at
once would reduce frustration, if not my chocolate intake!
* "all" being those relating (only) to this password selection task -
"all" would take much too long!
PS I'm on-vacation, so I'm eating whatever I want...
Jokes aside, haven't we discussed this before?
Question: are the criteria all dependent upon a single value or factor,
eg into which (statistical) "bucket" or category does my age fit?
(child, youth, adult, old-f...)
Alternately, if there are several independent factors (password-length,
content-characters), might fitting test-data into a "decision table"
help to clarify (all!) the various possible combinations of 'inputs' and
their corresponding 'outputs'?
ie it is not really a coding problem, but rules and logic?
(which should be clarified before fingers touch keyboard!)
--
Regards =dn
More information about the Tutor
mailing list