Here is my code for the above tasks for a Fibonacci sequence. I was told that I indented incorrectly, but I still couldn't figure out why it happened. Can anyone have a look for me, please? I'm very grateful for any help. Also, my code worked for task 1 but not for task 2. The error i got is IndentationError: unindent does not match any outer indentation level, which is really frustrating after hours of trying to sort things out.
Task 1 The first 10 numbers of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 The sequence is generated from the first two numbers (0 and 1), and every subsequent number is the sum of the previous two numbers. What is the largest number in the Fibonacci sequence smaller then 10^ 22?
Task 2 Rewrite your previous Fibonacci code as a function taking as arguments one or two arguments. If there is one argument, print all the Fibonacci numbers up to that number. If there are two arguments, print all the Fibonacci sequence numbers between the two arguments.
x0,x1=0,1
while x1 < 1e22:
x0,x1=x1,x0+x1
print x1
#end of task 1
def fibo(xmax,xmin=0):
x0,x1 = 0,1
while x0 <= xmax:
x0,x1=x0,x0+x1
if x0 >= xmin:
print x0
print fibo(60,6)
#end of task 2
fibofunction, sincex0is always 0 and thereforex0 <= xmaxis true in each iteration. - tamasgal