Last active
December 3, 2020 05:41
-
-
Save sshehrozali/17ac4caa2170a3efea85f45d6b6d3e34 to your computer and use it in GitHub Desktop.
Python program for arthmetic progression (A.P)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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