buran and ichabod801 provided great examples how to improve code.
I would suggest to add input validation mimicking real world scenarios. Currently, if user enters float, letter etc which can't be converted to int program will throw ValueError.
One possible way:
I would suggest to add input validation mimicking real world scenarios. Currently, if user enters float, letter etc which can't be converted to int program will throw ValueError.
One possible way:
def validate(request): """Return allowed input in range 0-9""" allowed = range(10) m = ('Expected integer in range 0 - 9 ' '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 you can write in game code:
pick = validate('Pick number between 0 and 9: ')
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.