每当我试着输入“线虫”时_小.gff,程序给出“无法打开”的打印语句。不过,我想把它打开。为什么会这样?你知道吗
print("Gene length computation for C. elegans.")
print()
file1 = "C.elegans_small.gff"
file2 = "C.elegans.gff"
user_input = input("Input a file name: ")
while user_input != file1 or user_input != file2:
print("Unable to open file.")
user_input = input("Input a file name: ")
if user_input == file1 or user_input == file2:
break
您的代码不正确,因为您使用的是
or
而不是and
。你知道吗假设用户输入file1,那么if语句是
False or True
。你知道吗因为它是
or
而不是and
,如果其中一个语句是true
,它仍将在while循环中。中断while循环的唯一方法是输入同时等于file1和file2。你知道吗这里是使用
and
时代码的固定版本。你知道吗而且,这部分也没用。这是因为while循环将检查它并自行中断,因此不需要if语句来中断它。你知道吗
相关问题 更多 >
编程相关推荐