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
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
+ 6
(@visph he forgot parenthesis on "print")
+ 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?
+ 2
( @VH: oh yes... I see that when I try to run it ;) )
+ 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 ^^
+ 2
I've just post in commentary section of your code ;)
+ 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.