Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 2

4 bytes removed, 13:08, 1 August 2017
PART 2 - Using IF/ELIF/ELSE Statements
print('b is greater than a')
</source>What happened?<br><br>This is neat, but what if 'a' is 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. Finally, we include the ELSE statement - in this case, if 'a' is equal to 'b' (i.e. fails first test since 'a' is not greater than 'b' and fails second test since 'a' is not less than 'b', so they must be equal to check other).<br><br>
#Modify your program to looks like this:<source> a = 10
b = 10
if a > b: