0
사용자 정의 유효성 검증을 구현하려고합니다. 사용자의 응답이 "Y"또는 "N"이 아닌 "Q"가 아닌 경우, 사용자의 응답이 맨 위로 되돌아갑니다 . 그렇지 않으면 휴식.
Python의 사용자 정의 유효성 검사
두 가지 옵션은 올바른 응답이 제공된 경우에도 계속 반복됩니다. 여기
내가 무엇을 시도했다입니다 : 옵션 1 :
""" Use custom validation. """
while True:
n_put = input('Would you like to perform a new Google image search?' + user_options())
if n_put is not "Y" or not "N" or not "Q":
print('Invalid response. Please read the prompt carefully. ')
else:
break
옵션 2 :
""" Use custom validation. """
while True:
n_put = input('Would you like to perform a new Google image search?' + user_options())
if n_put is not any(["Y", "N", "Q"]):
print('Invalid response. Please read the prompt carefully. ')
else:
break
'[ 'Y', 'N', 'Q']에 n_put이 없거나 : n_put == 'Y'이고 n_put == 'N''이 아닌 경우 ... – cwallenpoole
[ 사용자에게 유효한 응답을 줄 때까지 입력 요청 [https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response] – wwii
@wwii , 내 질문은 여러 가지 조건을 말합니다. 루프에별로 도움이되지 않습니다. –