Dec-06-2019, 12:21 PM
I suggest to think more thoroughly about logic of your program.
For example: how should code handle situation when user enters neither 'yes' or 'no'?
My suggestion is to refactor code:
- input validation function - keeps asking for input until either yes or no is entered by user; as this is needed only for deciding what to do next, it should return True or False
- two branch conditional - play game; quit
- keep asking question (while True):
- make answer lowercase so that comparison is easier
- if answer is 'yes' return True; if 'no' return False (exits function)
- else print message to user (while loop continues)
Something along those lines:
For example: how should code handle situation when user enters neither 'yes' or 'no'?
My suggestion is to refactor code:
- input validation function - keeps asking for input until either yes or no is entered by user; as this is needed only for deciding what to do next, it should return True or False
- two branch conditional - play game; quit
if validated_answer('Lets play this game,shall we? (Answer yes or no) '): # play game else: # quit gameRegarding validation function:
- keep asking question (while True):
- make answer lowercase so that comparison is easier
- if answer is 'yes' return True; if 'no' return False (exits function)
- else print message to user (while loop continues)
Something along those lines:
def validated_answer(request): while True: answer = input(request).lower() if answer == 'yes': return True elif answer == 'no': return False else: print('Answer must be yes or no! ')
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.