Changes

Jump to: navigation, search

OPS435 Python Lab 2

516 bytes added, 10:57, 26 May 2017
PART 1 - Understanding WHILE Loops
:#Open ipython3<source>
ipython3
</source>A '''WHILE''' loop can be used to create a '''Determinant Loop'''. That expression term means that the number of loops (also referred to as: 'repetitions' or 'iterations') are already known or 'determined'in advance. Below is a determinant WHILE loop that will count to 5. Each time the loop is run, it will add one to the count variable, increasing the variables number.<br><br>
:#Issue the following at the ipython3 shell to see what happens:<source>
count = 0
count = count + 1
print('loop has ended')
</source>A WHILE loop can also be used as an '''Indeterminant Loop'''. That term means that the number of loops are '''unknown''' in advance. For example, the loop keeps on repeating until the user enters the correct data - we have no idea how many times that user will do that, since that is the job of the user running the script and NOT the programmer. Indeterminant Loops are extremely useful for '''error-checking''' in order to prevent incorrect data being accepted and causing the script not to perform correctly.<br><br>
:#Here is an example of guessing the correct password:<source>
password = ''
13,420
edits

Navigation menu