如何解决为什么我的while不只使用第一个条件并忽略第二个条件而没有两个条件循环?
我正在尝试设置使用'or'的两个条件的while not循环。本质上,我要求用户输入贷款类型,如果未输入两个贷款之一,它会打印出它不是有效的贷款类型,然后再次要求输入。但是,我的代码仅适用于第一个条件,而第二个条件则被忽略。
以下是我的代码:
loan = input('Enter the type of mortgage loan for the purchase of this property: \n').lower() #Asks for the type of mortgage loan
while not loan == 'fha' or loan == 'conventional': #Checks if input is fha or conventional,if not asks for input again
print("Sorry,that is not a valid loan type.")
loan = input('Enter the type of mortgage loan for the purchase of this property: \n').lower()
感谢您的帮助!
解决方法
一个不太混乱的选择是:
loan = input('Enter the type of mortgage loan for the purchase of this property: \n').lower() #Asks for the type of mortgage loan
while loan not in ("fha","conventional"):
print("Sorry,that is not a valid loan type.")
loan = input('Enter the type of mortgage loan for the purchase of this property: \n').lower()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。