T-Th 9:05 |
CS 1110: Introduction to Computing Using Python Fall 2012 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Main
About: Announcements Staff Consultants Times & Places Calendar Materials: Texts Python Command Shell Terminology Handouts: Lectures Assignments Labs Assessment: Grading Exams Resources: CMS Piazza (link) Piazza (about) AEWs FAQ Python API Style Guide Academic Integrity |
Loop ExercisesThere is a PDF version of these instructions, if you would prefer to have that instead. The purpose of this lab is to give you some practice with loop assertions (preconditions, postconditions, and invariants) and with while loops that process a range of integers. It is a mixture of coding exercises and answers to be written on paper. Requirements For This LabThe very first thing that you should do in this lab is to download the file lab10.py. You should create a new directory on your hard drive for this file. You will notice that this file has several function stubs. Part of your lab will be to complete these function stubs. We expect you to test that your code is correct, but we will not ask you to submit a unit test. You are all experienced programmers now, and should understand the value of testing without having to turn in your tests each time. If you would like to make a unit test, here is a copy of cunittest.py.
For this lab you will show your instructor the contents of If you get stuck, do not waste time. Ask the TA or consultant for help. Written ExercisesQuestions on Ranges
How many values are in the following ranges? The last one requires a formula in terms of
Assigning to Range VariablesEach line below asks you to write an assignment. We have done the first one for you to give you an idea of what we are looking for. It may help to recall the "follower minus first" rule.
Completing AssertionsEach line below contains an assertion P that is guaranteed to be true. Each line also contains an assertion R, which we would like to be true. In the righthand column, put a boolean expression that, when true, allows us to conclude that R is true. We have filled in the first one for you.
Preserving Invariants
Below is a precondition P, an assignment to a variable, and the same
assertion P as a postcondition. At the place indicated, place a
statement so that if P is true initially, it will be true afterward
(as indicated). The statement can be in English, if you are not sure how to
write it in Python, but make it a command to do something.
In the exercises below, Problem (a)
Problem (b)
Problem (c)
Problem (d)
Coding While-Loops
Start a new folder and download Each implementation must contain a while-loop. Write one at a time, implementing the specification that we give you. When a loop invariant has not been given (such as with the last function), write your own.
Make sure each function is correct before proceeding to the next one.
Do this by writing suitable calls in the interactive prompt or making
a unit test (though we do not ask that you turn in these tests). Use
enough different test cases so that you really are sure that the
function is correct. If the function uses a string value, make sure
that it works on an empty string (one whose length is 0).
File You may not finish these functions during the lab. Near the end of the lab, show an instructor or consultant what you have done so far. If necessary, complete the lab during the next week and show what you have done to the instructor or consultant then. |