简体   繁体   English

无论你输入什么,我总是得到 ID 不在列表中

[英]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.

相关问题 Python 和随机森林,无论我做什么,总是得到错误“ValueError:输入包含 NaN、无穷大或对于 dtype('float32')来说太大的值” - Python and random forest, always get error "ValueError: Input contains NaN, infinity or a value too large for dtype('float32')" no matter what i do GIMP Python无论我使用哪种格式,我总是会“无法解析颜色名称” - GIMP Python No matter what format I use I always get “unable to parse color name” 无论你赋予它什么值,Python结构总是保持在0? - Python structure always stuck at 0 no matter what value you assign to it? 无论字符串是否在列表中,始终输出“不在列表中” - Always outputs “is not in the list” no matter if the string is in the list or not 如果语句条件被忽略并直接进入 else 无论您输入什么 - If statement conditions being ignored and going straight to else no matter what you input 为什么我的 MLP 无论如何总是输出 -1? - Why is my MLP always outputting -1 no matter what? API 请求无论如何总是返回 404 - API requests always return 404 no matter what 尝试绘制Mandelbrot集-无论如何,始终获得纯黑图像 - Trying to plot Mandelbrot set - no matter what, always get plain black image 你调用after()方法后调用的是什么? - Does it matter what you call after() method with? 如何在我的 python 脚本中重新启动 main() function? 无论我添加什么输入,程序都会重新启动 - How do I restart the main() function in my python script? The program restarts no matter what input I add
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM