Python code for the following series.
1 2 3 4 5 1 3 5 7 9 1 4 7 10 13 1 5 9 13 17....N terms.
Share
Python code for the following series.
1 2 3 4 5 1 3 5 7 9 1 4 7 10 13 1 5 9 13 17....N terms.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
def series(j):
i=1
sum=0
c=1
while i<6:
sum=sum+c
c=j
print(sum,end=" ")
i+=1
j=1
while j<5:
series(j)
j+=1
Explanation:
Question:-
It is a very interesting question....only a logic is required to understand this series.
In first 5 terms, the difference is 0(1,2,3,4,5)
In next five terms, difference is 1(1,3,5,7,9)
In next five terms, difference is 2(1,4,7,10)
And after each 5th term the number returns to 1 and the difference increases numerically
Since we found this logic, now code which I am going to write is based on this logic.
___________
Code:-
#code written [email protected]
n=(int)(input("Enter a number:"))
a,b,c=1,1,1
for i in range(1,n+1):
print(a,end=" ")
a+=b
c+=1
if(c>5):
c=1
b+=1
a=1
__________
Variable Description:-
__________
•Output Attached