Function Name: printFibonacci() Your job is to write a function that takes in two parameters and prints out a Fibonacci sequence (In the same line, separated by commas!) using those parameters. A Fibonacci sequence is produced by adding the two preceding numbers together to produce the next integer. The two parameters the user inputs will be the first two numbers you add to start your sequence. The function should stop when the last number printed is more than 300. Remember, the numbers must be printed in the same line with commas separating them. It's okay if the output wraps around to a new line. The key is that you print a single String. You don't need to print the parameters as a part of your output. You can also assume that the user will always input at least 1 nonzero parameter.
It should look like this:
>>> printFibonacci(1,9)
10,19,29,48,77,125,202,327
>>> printFibonacci(2,3)
5,8,13,21,34,55,89,144,233,377
python>>> printFibonacci(1,1)
2,3,5,8,13,21,34,55,89,144,233,377
so far I have this
def printFibonacci(a,b):
count = 0
max_count = 10
while count < max_count:
count = count + 1
old_a = a
old_b = b
a = old_b
b = old_a + old_b
print (old_a)
but it does not print in one line with comas and I don't know how to make it stop at 300.
Ok, so I have worked on it and now I have this which works much better:
def printFibonacci(a,b):
count = 0
maxnumber = 299
while b < 200:
begin = a+b
a , b = b , begin
start = a
end = b
print ((start)+ (end),end=",")
I am only having two little problems, one it is printing out a coma at the end of the string as well, how do I get rid of it?? and also the first number it is given me is already the sum of the first two and not the two parameters