Changes

Jump to: navigation, search

OPS435 Python Lab 2

58 bytes removed, 09:44, 26 May 2017
PART 2 - Using IF/ELIF/ELSE Statements
else:
print('b is greater than a')
</source>What happened?<br><br>:#But we may want to know This is neat, but what if 'a' is less than equal to 'b'. ? In order to make this work, we would need to perform another test! The 'elif' statement allows us to string together multiple if statement. This new statement 'elif' means: IF the first condition is False, it will check the second condition under 'elif'. HOWEVER, if the first condition is True, it will run the code indented under the first condition and SKIP the 'elif' statement.<source>a = 10b = 15Finally, we include the ELSE statement - in this case, if 'a > ' is equal to 'b: print' (i.e. fails first test since 'a ' is not greater than 'b')elif and fails second test since 'a < b: print('b is greater not less than a'b', so they must be equal to check other).<br></sourcebr>:#In Issue the event that we want to know if 'a' and 'b' are equal to each other, we could add another 'elif' using following at the '==' equal signs, but instead lets use 'else'. The 'else' statement will run the code indented under it only when all the 'if' and 'elif' statements above are False. ipython3 shell:<source>
a = 10
b = 15
13,420
edits

Navigation menu