Python if-else within loop not working (skips if) -
def searcher(): mun = raw_input("enter name of city> ") pal = mun.replace(' ', '') state = raw_input("enter state abbreviation> ") city = pal + state city = city.upper() r in range(sheet.nrows): c in range(sheet.ncols): cell = sheet.cell(r, c) if cell.value == city: loc = r else: print "not found" cell = sheet.cell(loc, 15) why last if-else skips 'if' , print not found infinitely?
you should have state variable found
# start out false found = false r in range(sheet.nrows): c in range(sheet.ncols): cell = sheet.cell(r, c) if cell.value == city: loc = r found = true # set true if find value # now, loops done. if not found: print "not found"
Comments
Post a Comment