error handling - Python program just stops running? -


while true:     chunks = []      x in range(len(new_match_list)):         if new_match_list[x] == id_input:             chunks=[new_id_info_list[x:x+7] x in range(0, len(new_id_info_list), 7)]      if len(chunks) == 0:         id_input = input("please choose number list provided, , enter correctly time!")      if len(chunks) > 0:         print (chunks[x])         break 

i'm having problem program, shows no error stops running, pauses minute, stops.

for example, program stops after producing:

here list of complaint ids can choose , ask : ['1344139', '1344055', '1343332', '1343188', '1343131', '1341190', '1340441', ] choose number list, , enter in. type in 'quit' if want quit program: 1344139  ..... 

there no error message produced whatsoever.

the goal of code print out list of data, containing 7 pieces of information (such zip code, state) specific id number.

if id number entered not in list of id numbers (aka new_match_list), "chunks" remain blank (hence, len(chunks) 0), , user forced re-enter id number until matches 1 on (new_match_list).

if id number match, should fill out (chunks) , print out specific part ([x]) of (chunks) related id.

what can fix error?

edit: i've tried different ways fix error, such substituting:

len(chunks) == 0: 

with

if id_input not in new_match_list: 

but nothing has worked. program stops without giving me error

your question little unclear, suspect when control reaches print (chunks[x]) want x have value had when new_match_list[x] == id_input true. if so, need put break statement last line of if block, i.e., after chunks=[new_id_info_list... line. and, paul cornelius mentioned, need change variable in list comprehension x doesn't clobbered.

however, there's better way find first matching entry in list: use .index() method. need put inside try: ... except block; alternatively, use in operator test id in list before attempting fetch index.


Comments