This program generates the Fibonacci sequence up to a given number of terms.
n =
int(
input(
"Enter the number of terms: "))
t1, t2 =
0,
1
print(
"Fibonacci Series:", t1, t2, end=
", ")
for _
in
range(
3, n +
1):
nextTerm = t1 + t2
print(nextTerm, end=
", ")
t1, t2 = t2, nextTerm
No comments:
Post a Comment