Can someone help me with python??

I am trying to write a function to compute the Nth Fibonacci number where N is a parameter
This is what I got so far...But it just wont output..
1
2
3
4
5
6
7
8
9
10
 def f (n):
	a=0
	b=1
	for i in range (0,n):
		print (a)
		temp=a
		a=b
		b=temp+b
		return a
	f(15)
Maybe reading the Python Tutorial would help?
https://docs.python.org/3/tutorial/modules.html
Python uses whitespaces as delimiters. f(15) is part of the function there. So it's not getting called.
1
2
3
4
5
6
7
8
9
10
def f(n):
	a=0
	b=1
	for i in range (0,n):
		print (a)
		temp=a
		a=b
		b=temp+b
		return a
f(15)
Last edited on
closed account (18hRX9L8)
Cheraphy wrote:
Python uses whitespaces as delimiters.

Continuing with this, you are returning in the loop instead of after it...

1
2
3
4
5
6
7
8
9
10
11
12
def f(n):
	a=0
	b=1
	for i in range (0,n):
		print (a)
		temp=a
		a=b
		b=temp+b
	return a # Return after loop completes...


f(15)
Last edited on
Topic archived. No new replies allowed.