0

Why can't i print the sum of my list?

Trying to find sum of even fibonacci no's < 4m. Got this far but getting syntax er. can anyone help? Number = 100 i = 0 First_Value = 0 Second_Value = 1 while(i < Number): if(i <= 1): Next = i else: Next = First_Value + Second_Value First_Value = Second_Value Second_Value = Next if Next <= 4000000 and Next % 2 == 0: print sum(Next) i = i + 1

23rd Jan 2017, 1:10 PM
Dustysoul
Dustysoul - avatar
7 odpowiedzi
+ 6
Number = 100 i = 0 First_Value = 0 Second_Value = 1 while(i < Number): if(i <= 1): Next = i else: Next = First_Value + Second_Value First_Value = Second_Value Second_Value = Next if Next <= 4000000 and Next % 2 == 0: print(sum(Next)) i = i + 1
23rd Jan 2017, 1:13 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 6
(@visph he forgot parenthesis on "print")
23rd Jan 2017, 1:15 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
Indentation is very important ( essential ) in Python: your last 'if' statement doesn't have clean indent... maybe you've got an error for this reason?
23rd Jan 2017, 1:14 PM
visph
visph - avatar
+ 2
( @VH: oh yes... I see that when I try to run it ;) )
23rd Jan 2017, 1:17 PM
visph
visph - avatar
+ 2
Still an error when print syntax and indentation corrected... about the use of sum() function: it's parameters require iterable and 'Next' value isn't ^^
23rd Jan 2017, 1:25 PM
visph
visph - avatar
+ 2
I've just post in commentary section of your code ;)
23rd Jan 2017, 3:56 PM
visph
visph - avatar
+ 1
visph, yes after correcting the print syntax and indentation i'm still getting an error (typeError: 'int' object is not iterable ) Any idea how i can fix this? Thanks for your help so far, the community here is incredible. I've made the code public on the code playground if anyone has any ideas.
23rd Jan 2017, 3:10 PM
Dustysoul
Dustysoul - avatar