From a89a8f80dfe71311ce96ccb8ee631223689e3655 Mon Sep 17 00:00:00 2001 From: Rohit Prasan Mandal <50553530+xiaowuc2@users.noreply.github.com> Date: Wed, 27 May 2020 14:46:13 +0530 Subject: [PATCH] P002 update.py without using function --- python/p002.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/p002.py b/python/p002.py index 14086b76..1ff2caca 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())