I want to apply loop but i don't know how to apply it on my code

3671 views python
7

here's my code

#Program for calculating the nTH Term
sequence=range(0,40,3)
a=int(input("The first term is:"))
d=int(input("The common difference is:"))
n=len(sequence)
print("The number of terms is:",n)
print("The last term of sequence is: ")
Tn=a+((n-1)*d)
print(Tn)

how can i make this code to run again using if condition and with new values which i will input again ORrr i just have to put an if condition and copy/paste my code inside it?

answered question

inside a while loop?

1 Answer

11

while True:
    sequence=range(0,40,3)
    a=int(input("The first term is:"))
    d=int(input("The common difference is:"))
    n=len(sequence)
    print("The number of terms is:",n)
    print("The last term of sequence is: ")
    Tn=a+((n-1)*d)
    print(Tn)

posted this

Have an answer?

JD

Please login first before posting an answer.