Thursday, January 1, 2015

Using the not Logical Operator and Compound Conditions

In the program below, username is initialized as an empty string so it starts out as False, making not username True. The not username is True as long the string is empty. This forces the username to enter a username, or the loop will continue to ask for username until something is entered. Once an input is entered for username the not username is False and the loop stops, moving the program forward to password, which is set up in a similar manner. The table below summarizes the logic:

Username
not username
True
False
False
True

The program also demonstrates the use of and / or compound conditions. See examples below.


 

No comments:

Post a Comment