Dec-30-2020, 08:01 AM
Some observations.
There is the repetition of input validation. If such pattern emerges then it is clear that function should be used. Currently the code is not DRY (Don't Repeat Yourself). Simple validation function should be used, something along those lines:
There is the repetition of input validation. If such pattern emerges then it is clear that function should be used. Currently the code is not DRY (Don't Repeat Yourself). Simple validation function should be used, something along those lines:
def validate(request): while True: answer = input(request) try: return abs(float(answer)) except ValueError: print(f'Expected numeric value but {answer!r} was entered')Now you can use this or similar function when you need to validate user input to be numeric and absolute value. You can be 'clever' and use loop and unpacking while using it:
low, high = (validate(f'Enter the {boundary} measurement value: ') for boundary in ['minimum', 'maximum'])
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.