python logical errors