在此while循环中,我如何不接受'Yes'或'No'以外的字符串值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在此while循环中,我如何不接受'Yes'或'No'以外的字符串值相关的知识,希望对你有一定的参考价值。
我对编程非常陌生,所以请原谅这个愚蠢的问题。我如何进行此循环,以便如果此人输入随机字符串(不是“是”或“否”),它将返回“无效响应”?
name = input("What's your name? ")
understanding = input(", do you understand while loops in python\n(Yes or No)? ".format(name))
while understanding.lower() != 'yes':
print("Ok, , while loops in Python repeat as long as a certain Boolean condition is met.".format(name))
understanding = input(", now do you understand Python while loops?\n(Yes or No)? ".format(name))
print("Great news ! It's good to hear that you understand these loops now! Let's move on!".format(name))
答案
也许像这样
if understanding.lower() not in ('yes','no'):
print('Invalid response')
以上是关于在此while循环中,我如何不接受'Yes'或'No'以外的字符串值的主要内容,如果未能解决你的问题,请参考以下文章
java.sql.SQLException: Access denied for user 'roo'@'localhost' (using password: YES
为什么当我开始输入更改服务类型或'4'时,循环会停止????以及其他一些问题
mysql打不开,提示#1045 - Access denied for user 'root'@'localhost' (using password: YES)