Changes

Jump to: navigation, search

OPS435 Python3 Lab 2

22 bytes added, 15:08, 12 September 2019
PART 1 - Using IF Statements
if True:
print('This print is apart of the if statement')
</source>What happened when you ran this code? It is important to note a couple of things with the IF statement:<ul><li>When the expression in an IF statement '''evaluates to True''', it runs the code that is indented underneath it. In this case, we can use the boolean value "True" to make this happen, or test to see if a expression determined is evaluated to true or false.</li><li>However, if the If expression in the IF statement evaluates to '''False''', then it will not run the code indented underneath it. Any code not indented under the if statement will perform normally as the main program and is NOT associated with control flow statement.</li><li>Indentation means to start a line with spaces or tabs before your text. Using '''indentation''' will direct the script what code will run as part of the IF statement and which code will run regardless. Also, using indentation makes it easier for a programmer to identify Control Flow statements. From this point on, be VERY careful and consistent with indentation because it will affect how your code works. </li></ul>
<blockquote style="margin-left:35px;">{{Admon/important|style="padding-left:25px"|4 spaces|While python allows some flexibility with your indentation - please don't be creative with it. Always use 4 spaces for each new block. There will be exceptions later on, but start with this now. You may find it helpful to configure your editor to insert for spaces instead of a tab when you press the tab key.}}</blockquote>
<ol><li value='3'>Try the following 3 lines, indenting the second and third lines, but NOT the fourth line:<source lang="python">
1,760
edits

Navigation menu