While循环不断重复,即使满足了使其中断的标准


fenced = '0' # Sets the criteria to an incorrect value
while fenced.lower() != 'fully' or 'partially' or 'none':
fenced = input("Is the property fully fenced or partially fenced? (Answer 'Fully', 'Partially' or 'None') ")
if fenced.lower() != 'fully' or 'partially' or 'none':
print("Invalid Input. Please try again.")
elif fenced.lower() == 'fully' or 'partially' or 'none':
myfile.write("Fenced:n" + str(fenced) + 'n')
break

该代码应该在用户输入"while"之后中断while循环;完全""部分";,或";无">

试试这个

fenced = '0' # Sets the criteria to an incorrect value
while fenced.lower() != 'fully' or 'partially' or 'none':
fenced = input("Is the property fully fenced or partially fenced? (Answer 'Fully', 'Partially' or 'None') ")
if fenced.lower() != 'fully' and 'partially' and 'none':
print("Invalid Input. Please try again.")
elif fenced.lower() == 'fully' or 'partially' or 'none':
myfile.write("Fenced:n" + str(fenced) + 'n')
break

最新更新