On 2020-12-17, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:
>>
>
> The main concern is that you are using a RECURSIVE call. It is much
> better for such input checking to use an ITERATIVE (loop) scheme.
>
> def marriage():
> #loop forever
> while True:
> #get response from user
> maritals = input("Married: Yes/No ?").title()
> #if response is good, exit (break) the loop
> if maritals in ["Yes", "No"]: break
> #otherwise display error message and repeat loop
> print("Try again. Please respond with Yes or No")
> #return valid response
> return maritals
>
>
It makes sense for me now, better logic used here than mine.
I've never met that way used in * if maritals in ['Yes', No']: * ,
it makes code elegant.
So it's not good to use calling function itself (recursive call), I get it now.
--
https://mail.python.org/mailman/listinfo/python-list