Looping Exercises
From WLCS
Objective:
- To become well-learned in the way of the while loop
Resources:
- [Media:PythonWhileLoops.pptx]
- HTTLACS: Ch 6 - Iteration
Directions:
- For each of the following sequences, first prompt the user for a number N
- Use while loops to generate the following sequences
- Powers of 2
- Print out the first N terms of the sequence
- 1, 2, 4, 8, 16, 32, 64, 128, ...
- Fractions Sequence
- Print out the first N terms of the sequence
- 1/1, 1/2, 1/3, 1/4, 1/5, ...
- Summation up to N
- Use a loop to add up all the numbers from 1 up through N
- Example: N = 3 would total 6
- Example 2: N = 10 would total 55
- Fibonacci Sequence (HINT: use multiple variables)
- Print out the first N terms of the sequence
- 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
- Factorial Sequence (HINT: use multiple variables)
- Print out the first N terms of the sequence
- 1, 1, 2, 6, 24, 120, ...