Python Codes for (Geometric & Arthematic Progression)
Arthematic Progression
Code1:-
import numpy as np
import math
#......Python program for Arthematic Progession........#
def printAP(a,d,n):
first_term=a
for i in range(1,n+1):
print(first_term,end =' ')
first_term = first_term + d
a = int(input("Enter the starting number: "))
d = int(input("Enter the Comman Difference: "))
n = int(input("Enter the nth term : "))
printAP(a,d,n)
OUTPUT
>>>
=============== RESTART: D:/Desktop/Python(TUT)/ArthematicP.py ===============
Enter the starting number: 2
Enter the Comman Difference: 1
Enter the nth term : 5
2 3 4 5 6
>>>
Geometric Progression
Code2:-
import numpy as np
import math
#......Python program for Geometric Progession........#
def printGP(a,r,n):
for i in range(0,n):
curr_term = a * pow(r,i)
print(curr_term,end = " ")
a = int(input("Enter the starting number: "))
r = int(input("Enter the Comman Ratio: "))
n = int(input("Enter the nth term : "))
printGP(a,r,n)
OUTPUT
>>>
=============== RESTART: D:/Desktop/Python(TUT)/GeomatricP.py ===============
Enter the starting number: 2
Enter the Comman Ratio: 3
Enter the nth term : 5
2 6 18 54 162
>>>