Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/p002.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ def compute():
x, y = y, x + y
return str(ans)

#---------------------------------OR---------------------------------------#
# WITHOUT USING FUNCTION
ans = 0
x = 1 # Represents the current Fibonacci number being processed
y = 2 # Represents the next Fibonacci number in the sequence
while x <= 4000000:
if x % 2 == 0:
ans += x
t=x+y
x=y
y=t
print(ans)


if __name__ == "__main__":
print(compute())