Jul-24-2018, 10:40 AM
One way to validate input is write a separate function, something like that:
def validate(request): """Return allowed input in range 1-100""" allowed = range(1, 101) m = ( (f'Expected integer in range 1 - 100 ' f'but input was') ) while True: answer = input(request) try: answer = int(answer) if answer in allowed: return answer except ValueError: print(f'{m} {answer}') else: print(f'{m} {answer}')Then it's just:
score_to_grade(validate('Enter score: '))and now it is not important how score_to_grade handles out of range values.
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.