Python: Code is ignoring the if and else

kevin4fong at gmail.com kevin4fong at gmail.com
Fri Aug 2 21:44:44 EDT 2013


On Friday, August 2, 2013 6:39:43 PM UTC-7, John Ladasky wrote:
> On Friday, August 2, 2013 5:40:52 PM UTC-7, kevin... at gmail.com wrote:
> 
> >     Basically, my code is ignoring the if's and else's. I don't get why.
> 
> > Everything appears to be positioned correctly, but for some odd reason, even
> 
> > after an if, the program also runs the else as well.
> 
> 
> 
> Look carefully at your indentation.  One "else" statement is at the same indentation as a "for" statement rather than an "if" statement.  So what, you say?
> 
> 
> 
> http://docs.python.org/2/tutorial/controlflow.html
> 
> 
> 
> "Loop statements may have an else clause; it is executed when the loop terminates through exhaustion of the list (with for) or when the condition becomes false (with while), but not when the loop is terminated by a break statement."
> 
> 
> 
> I don't know of any other computer programming language besides Python which has the "for...break...else" idiom.  However, I know quite a few that do not.  I find it useful in many situations.

Yeah, I already know about that. But if I try to change it, I'm not even able to start the program. If I try to change the if statement that it corresponds with, I get a an error saying "card" is not a global. And if I try to shift it in, for some reason...the program runs through the MISS line multiple times.



More information about the Python-list mailing list