[英]Why is my code only reading the first condition and not checking for the second?
[英]Why is my while not loop with two conditions only using the first condition and ignoring the second condition?
我正在尝试设置一个 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.