Python searching list thats inputted by user -


hi im trying write program uses repetition statement allow users enter 5 numbers , stores them in list.then allow user search list number entered user , indicate whether number has been found or not. im quite stuck on one, i've made of effort can

data =raw_input('please input 5 numbers: ') print data  search =raw_input('search numer: ') sublist in data:    if sublist[1] == search:     print "found it!", sublist  break         

you might try this

numbers = []  while len(numbers) < 5:     number = raw_input('please input 5 numbers: ')     if number.isdigit():         numbers.append(int(number)) #may want use float here instead of int     else:         print "you entered isn't number"  search = raw_input('search numer: ') if int(search) in numbers:     print "found it!" 

your code indicates may using sublists unclear how creating them.


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -