Please use your Python system (IDLE or something else) to compute the following. Be prepared to show your work!
Answer: (a) does not include 19, as range() goes up to but not including the upper number. (c) will work, but is clumsy and has an unnecessary if statement. (d) works, but uses a construct (while) intended for an indefinite loop, not a definite one. So (b) is the best answer.
Answer: (a) is obviously wrong, as it doesn’t use a for loop. (d) is wrong, as the continue causes the loop to be executed again, starting at the beginning of the loop. Both (b) and (c) are correct; which on e you should use depends on whether you will use the input in the loop and not just in the conditional. If you will use the input elsewhere in the loop, then (c) is better; if it will only be used in the conditional, (b) would be more appropriate.
|
MHI 289I, Programming for Health Informatics Version of October 14, 2020 at 11:53PM
|
You can also obtain a PDF version of this. |