Lucas Series - Python Language
softetechnologies
13-10-2020    149 times
Lucas Series Python

Write Python code to print terms of the Lucas Series up to n terms (n is user input) using a for loop. Also, find the sum of the even value terms (2, 4, 18 etc.) and odd value terms (1, 3, 7 etc.) separately. Print those sum values for up to the first 20 terms of the series.
The Lucas series is given by:
2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, … up to n

N=int(input("Enter Terms : "))
a=evensum=2
b=oddsum=1
print(a,",",b,end='')
for i in range(3,N+1):
    k=a+b
    a,b=b,k
    print(",",k,end='')
    if(i<=20):
        if(k%2==0):
            evensum=evensum+k
        else:
            oddsum=oddsum+k
print("Sum of the even terms :  ",evensum)
print("Sum of the odd terms :  ",oddsum)
Private Teacher
softetechnologies
softetechnologies
    Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
    Related Post
  Query About the post