"If" Statements |
if and else To use an "if" statment in your program, you'll define a set of conditions and some action that you want the computer to perform if the conditions are met. Then you'll define another set of actions that you want the computer to perform if the conditions are not met. This set of actions gets an "else" statement. For example: if x < 0: print x, " is less than zero." else: print x, " is not less than zero." |
jump
to top
|
elif Suppose you have three or more sets of circumstances that you want to define. You could put "if" statements inside of other "if" statements but that gets very complicated. A better solution is to use the world "elif," which is short for "else if." For example: if temperature < 55: print "It's cold outside today!" elif (temperature >= 55) and (temperature <= 75): print "The weather is fine today." else: print "It's a scorcher!" |
jump
to top
|