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!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

6th Aug 2020, 8:11 PM
Olusanwo Isaac
18 Answers
+ 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
8th Aug 2020, 6:05 PM
Boniface Delali Dakey
Boniface Delali Dakey - avatar
7th Aug 2020, 5:19 AM
MSN
MSN - avatar
+ 5
Jayakrishna🇮🇳 i know it :)
6th Aug 2020, 9:37 PM
Julia Shabanova
Julia Shabanova - avatar
+ 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)
6th Aug 2020, 8:42 PM
Julia Shabanova
Julia Shabanova - avatar
+ 3
Error in line: el =..
6th Aug 2020, 9:10 PM
Julia Shabanova
Julia Shabanova - avatar
+ 3
Jayakrishna🇮🇳 it was in first code, even numbers with first 2,2
6th Aug 2020, 9:28 PM
Julia Shabanova
Julia Shabanova - avatar
+ 1
thank you very much julia, i'd implement that!!!
6th Aug 2020, 8:45 PM
Olusanwo Isaac
+ 1
range(2,400000) cause Error in list indexes. Initially you have 2 elements indexes 0,1 but so list1[2] 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.
6th Aug 2020, 9:16 PM
Jayakrishna 🇮🇳
+ 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..
6th Aug 2020, 9:36 PM
Jayakrishna 🇮🇳
+ 1
Julia Shabanova ok. Olusanwo Isaac you should start from 1,2. from the description and actually i think 30 range is enough..
6th Aug 2020, 9:52 PM
Jayakrishna 🇮🇳
+ 1
thank you very much, i apperiate both of you
6th Aug 2020, 9:54 PM
Olusanwo Isaac
+ 1
🇧🇩Saadman Nuheen🇧🇩 , thanks for reminding, i forgot it was even numbers i need... thank you
7th Aug 2020, 5:49 AM
Olusanwo Isaac
0
it still says indexerror...
6th Aug 2020, 9:03 PM
Olusanwo Isaac
0
ok i'd do that
6th Aug 2020, 9:23 PM
Olusanwo Isaac
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
6th Aug 2020, 9:32 PM
Olusanwo Isaac
0
Julia Shabanova , i assumed the (2,2) cause i was asked to print even fibonacci numbers
6th Aug 2020, 9:36 PM
Olusanwo Isaac
0
Jayakrishna🇮🇳 thanks, the highest range was 4000, and it wasn't readable
6th Aug 2020, 9:39 PM
Olusanwo Isaac
27th Aug 2020, 5:00 PM
Olusanwo Isaac