How to do it...

We'll look at a six-step process that outlines the core of designing this kind of iterative algorithm. This is the kind of thing we need to do when a simple for statement doesn't solve our problem.

  1. Define done. In our case, we'll have two copies of the password, password_text and confirming_password_text. The condition which must be true after the loop is that password_text == confirming_password_text. Ideally, reading from people (or files) is a bounded activity. Eventually, people will enter the matching pair of values. Until they enter the matching pair, we'll iterate indefinitely.

There are other boundary conditions. For example, end of file. Or we allow the person to go back to a previous prompt. Generally, we handle ...

Get Modern Python Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.