当用户输入一个数字并在list.if值中搜索时,列表如何工作,程序终止,如果找不到,则找不到输出 [英] How a list works when user enters a number and that is searched for in the list.if value found, the program terminates and if not found outputs not found
本文介绍了当用户输入一个数字并在list.if值中搜索时,列表如何工作,程序终止,如果找不到,则找不到输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MaxIndex=7#The maximum amount of numbers
SearchValue=input("Please enter value")#The value user inputs
Found=False#Initially found set to false
Index=0
MyList=['25','34','98','7','41','19','5']
while Index:
if (Found==True)or(Index>=SearchValue):#The program terminates with this condition
Index=Index+1
if MyList['25','34','98','7','41','19','5']==SearchValue:
Found=True
print("The value found at location",Index)
else:
print("Value not found")
我尝试了什么:
我试过给一个真假条件,但程序始终给出未找到值条件
What I have tried:
I tried giving a true and false condition but the program always gives " Value not found"condition
推荐答案
转到索引& mdash; Python 3.3.6文档 [ ^ ]并研究如何使用列表。
Go to Index — Python 3.3.6 documentation[^] and study how to use lists.
这篇关于当用户输入一个数字并在list.if值中搜索时,列表如何工作,程序终止,如果找不到,则找不到输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文