COSC 235: Programming and Problem Solving
March 23, 2009

Joseph D. Sloan
sloanjd @ wofford.edu


Truth tables

See example.

Indefinite Loops

While Loops

while <test>:
   #body

See example.

Infinite Loops

Infinite Loops—if the test is always true, the loop won't terminate. With the interpreter, use a control-C. Here is an example of an infinite loop:

while true: print "hello"

Usually the problem with the test is more subtle. And, at times, infinite loops are useful.

Translating loops:
Definite -> indefinite (yes)
Indefinite -> definite (maybe)

Post-test idiom:

while True:
       ...
       if ...: break
       ...

Homework

Wednesday:

Add comments to your Energy Density calculator as described below. You should also check input values to insure that they are reasonable. Be sure to correct any existing problems as well including documentation. Submit the code as an email attachment.

Assuming you are trying to lose weight:
If ED is between 0 and 0.6, it is very low and you can eat the food without restraint;
If ED is between 0.6 and 1.5, it is low and you can eat with minor restraints;
If ED is between 1.5 and 4.0, it is medium and you should watch portions;
If ED is between 4.0 and 9.0, it is high and you should closely limit or avoid the food.
Alter your GUI so that it prints appropriate comments based on this information.


This page was created by Joe Sloan.
It was last modified around: 6 April 2009
Send mail to: sloanjd@wofford.edu