= 1
product = 0
count while count < 5:
= int(input("Enter an integer:"))
number *= number
product print("The total product is", product)
Pattern: accumulator
- An accumulator is the name we give to a variable that is updated at each loop.
- For example, identify the accumulator variables in the following code:
Example: Fibonacci sequence
= 1
acc1 = 1
acc2 = [1, 1]
fib = 10
length_fib = 1
i while i < length_fib:
= acc1 + acc2
next_number
fib.append(next_number)= acc2
acc1 = next_number
acc2 += 1
i print("The Fibonnaci sequence is", fib)