Texts: The Fibonacci sequence is a sequence of numbers where each number is the sum of the two numbers before it, starting with 0 and 1:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
We can generalize this sequence by choosing two arbitrary starting values a and b, with a ≤ b. For example, if we would start with 4 and 20 instead, we get:
4, 20, 24, 44, 68, 112, 180, 292, ...
Let fibo(a, b) denote the generalized Fibonacci sequence starting with a and b. For example, the two sequences above are respectively fibo(0, 1) and fibo(4, 20).
Write a Python program that first accepts two positive integers a and b (of which only a can be 0), followed by a sequence of nonzero integers until the user enters 0. The program then prints a line containing all the values in S (excluding the last 0) appearing in fibo(a, b), as well as the total number of printed values. The order in which the values are printed needs to be the same as the order in which they were submitted by the user. All values in the output should be separated by a comma followed by a single space. We refer to the examples below for the correct output format. If the given sequence S is empty (i.e. the first submitted value after a and b is 0), the output should be "No values given." If S is nonempty, but no value in S is in fibo(a, b), the output should be "No valid values."
Hints:
- Notice that there is never a comma or space after the last value in the output!
- For this assignment, you can assume that the input is always valid: the first two values a and b are integers with 0 ≤ a ≤ b and 0 < b, and all other values except the last one are nonnegative integers.
Example 1:
Input: 0 1 5 6 0
Output: 1 valid value: 5
Explanation: The first two values (0 and 1) indicate that we should consider fibo(0, 1). The user then enters the values 5 and 6, of which only 5 appears in fibo(0, 1). The last submitted 0 indicates the end of the submitted values.
Example 2:
Input: 4 20 3 9 28 181 0
Output: No valid values
Explanation: The first two values (4 and 20) indicate that we should consider fibo(4, 20). The user then enters the values 3, 9, 28, and 181, none of which appear in fibo(4, 20). The last submitted 0 indicates the end of the submitted values.
Example 3:
Input: 4 20 0
Output: No values given
Explanation: The first two values (4 and 20) indicate that we should consider fibo(4, 20). However, no values are submitted after that, so the output is "No values given."