diff --git a/python/p002.py b/python/p002.py index 14086b7..1ff2cac 100644 --- a/python/p002.py +++ b/python/p002.py @@ -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())