Skip to content

Instantly share code, notes, and snippets.

@sshehrozali
Last active December 3, 2020 05:41
Show Gist options
  • Save sshehrozali/17ac4caa2170a3efea85f45d6b6d3e34 to your computer and use it in GitHub Desktop.
Save sshehrozali/17ac4caa2170a3efea85f45d6b6d3e34 to your computer and use it in GitHub Desktop.
Python program for arthmetic progression (A.P)
# Ask for First term and Common difference
a = eval(input("\nEnter First Term: "))
d = eval(input("Enter Common difference: "))
# Extend the range to greater upper bound
for i in range(20000000000000000000000):
# Ask for nth term
n = eval(input("\nEnter nth term: "))
# Apply formula
Tn = a + ((n - 1) * d)
# Print Answer
print("\n------------------------------\nnth Term of the sequence: ", Tn, "\n------------------------------\n")
# Keep prompting till valid input
while (True):
ask = input("Do you want to continue? (Y / N)\nType Option: ")
if ask.upper() == "N":
print("\nThankyou!\n")
exit(0)
if ask.upper() == "Y":
break
if ask.upper() != "Y" and ask.upper() != "N":
print("Please Enter Correct Input\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment