Flag Variables | BUS 104 – Python Exam

To view the VIDEO for this concept, you must purchase Python Cram Kit or Lifetime Access. Already purchased? Click here to log in.

Flag variables explained

Remember practicing multiplication tables as a kid and your teacher repeatedly asking you what "5 x 9" was until you got it right?

In this situation, the flag variable was whether or not you got the problem correct.

If you answered the problem incorrectly, the teacher would continue the loop of asking you the question.

However, if you answered the problem correctly, the teacher end the loop and stop asking you the question.

In other words...

A flag variable is a boolean value that signals to a while loop whether or not to continue running.

Coding a flag variable

Let's take the situation above and apply it in Python terms to get a better idea of how it works. I've coded the majority of the program, that way we can focus on how the flag variable works.

PAID CONTENT

This is the end of the preview. To unlock the rest, get the Python Cram Kit or Lifetime Access.

Already purchased? Click here to log in.

Leave a Comment