[英]no matter what you input i always get ID is not in list plz
no matter what you input I always get an ID that is not on the list无论您输入什么,我总是得到一个不在列表中的 ID
ID = [45, 33, 27, 88, 103, 66, 71] #list
numberSought = input("Please enter ID number to find:") #input whith an input
found = False
n = len(ID)
k= 0
while found == False and k < n:
if numberSought == ID [k]:
found = True
k += 1# k += k == k = k + 1
if found == True:
print("ID is in the list at index", k - 1)
else:
print("ID is not in the list")
There is a much simpler way of doing the exact same thing:有一种更简单的方法可以做同样的事情:
ID = [45, 33, 27, 88, 103, 66, 71] #list
number = int(input("Please enter ID number to find:")) #input whith an input
if number in ID:
print(f"ID is in the list at index {ID.index(number)}")
else:
print("ID is not in the list")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.