 Please, if you see this post, there's a code i just wrote, I'm trying to print even Fibonacci numbers, check my activity for it. | SoloLearn: Learn to code for FREE!

+3

# Please, if you see this post, there's a code i just wrote, I'm trying to print even Fibonacci numbers, check my activity for it.

struggling with fibonacci, need proper correction to my code on my post in my àctivity, i'd be very happy, thank you https://code.sololearn.com/cCe3p8K1bgA7/?ref=app

+1

Olusanwo Isaac, why don't you consider using if statements because [2,2] isn't Fibonacci. Also, appending just the even numbers will cause an index error. Here's how I can help: a, b = 0, 1 for i in range(30): if b%2 == 0: print(b) a, b = b, a+b

+6

Solution: https://code.sololearn.com/c04x305Xp0WO/?ref=app

+5

Jayakrishna🇮🇳 i know it :)

+3

if I understood correctly and the first elements:2,2 list1 = [2, 2] for k in range (2,4000000): el = list1[k-2] + list1[k-1] list1.append (el) print (list1)

+3

+3

Jayakrishna🇮🇳 it was in first code, even numbers with first 2,2

+1

thank you very much julia, i'd implement that!!!

+1

range(2,400000) cause Error in list indexes. Initially you have 2 elements indexes 0,1 but so list1 produce error. Take range(40000) only... (means From 0) and also list[2,2] will result wrong output for fibonacii. take list1[0,1] instead.

+1

Olusanwo Isaac list1 = [1, 2] for i in range (40): el = list1[i] + list1[i+1] list1.append(el) print (list1) Julia Shabanova initially first numbers are 0,1,1,2,3,5... So 2,2 is not correct. But if we want as 2,2 then its our wish..

+1

Julia Shabanova ok. Olusanwo Isaac you should start from 1,2. from the description and actually i think 30 range is enough..

+1

thank you very much, i apperiate both of you

+1

🇧🇩Saadman Nuheen🇧🇩 , thanks for reminding, i forgot it was even numbers i need... thank you

0

it still says indexerror...

0

ok i'd do that

0

thank you, i've done it, but it was too much to run here, so i reduced it... i got the question from here tho : http://www.projecteuler.net, that's if you don't know it, thanks once again

0

Julia Shabanova , i assumed the (2,2) cause i was asked to print even fibonacci numbers

0

Jayakrishna🇮🇳 thanks, the highest range was 4000, and it wasn't readable

0

thanks Boniface Delali Dakey