You will recall that the templates for the range
function which gives a list of integers ased on integer parameters:
As a shorthand for function templates, we will follow the common practice of putting optional parameters in square brackets, so the templates above could be shortened to
In the interpreter try the invoking range with the
following arguments and noting the results:
Start | Stop | Step |
1 | 10 | 1 |
1 | 11 | 1 |
50 | 100 | 5 |
range can also be used to count down. Provide an
example that counts down from 10 to 1, and test it.
Write a program that will compute the sum 1 + 2 + 3 +
… +
n. The user will specify the value of n You program
will
need to
Henceforth, use the style of Zelle, with all the code indented under a heading like
def main():
and ending with the (unindented line) that executes your main function:
main()
Write a program to sum a series of numbers entered by the
user. The program should first prompt the user for how many
numbers are to be summed. It should then prompt the user for
each
number and once at the
end (at least in your final version) print the sum with a
label. Outline
what your program must do as in task 2. You can write an
outline
in the idle editor, first without worrying about comment marks.
Then you can convert your outline to a comment by selecting
the
lines and then selecting in theFormat Menu, "Comment out lines".
Then convert your outline to a Python program.
Try to get check off in person, as described in Lab 2.
If you need to submit to Blackboard, it is easiest if all programs are in one file. You can cut and paste your programs (nothing from Task 1) all into one file and modify the function headings so they are different. They could be main2(), main3(), and maybe extra1() if you did the first extra credit problem.... Then make the lines that execute each program at the end match the names in the definitions at the beginning. Make the file submitted contain 'lab' and number and at least one user ID run together, like lab3aharrin.py or lab3aharrin-npodder.py.