Question: Implement function generateSequence(startNumber, factor, offset, stopNumber) that generates a sequence of numbers as follows. The sequence starts with startNumber. Let currNumber represent the current number

Implement function generateSequence(startNumber, factor, offset, stopNumber) that generates a sequence of numbers as follows. The sequence starts with startNumber. Let currNumber represent the current number in the sequence. Then, until the currNumber is equal to stopNumber, the following rule is used to update currNumber:

-if currNumber is even, the next number is currNumber / 2.

-if currNumber is odd, then next number is ((currNumber * factor) + offset)

Assume all inputs are positive integers and that startNumber is greater than or equal to stopNumber. generateSequence should 1) print each number of the sequence on a separate line, and 2) print information about the length of the sequence (i.e. the number of numbers generated in the sequence). Your function should use a single while loop.

>>> generateSequence(5, 3, 3, 3)

5

18

9

30

15

48

24

12

6

3

Length of sequence: 10

>>> generateSequence(5, 3, 1, 1)

5

16

8

4

2

1

Length of sequence: 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!