Review, suggestion etc?

Bischoop Bischoop at vimart.net
Thu Dec 17 18:05:46 EST 2020


On 2020-12-17, Bischoop <Bischoop at vimart.net> wrote:
> On 2020-12-17, Dennis Lee Bieber <wlfraed at 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.

--
Thanks


More information about the Python-list mailing list