final python logic problem