-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfibonacci.py
32 lines (25 loc) · 919 Bytes
/
fibonacci.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def generate_fibonacci(n):
t1, t2 = 0, 1
print("\nFibonacci Sequence up to", n, "terms:")
print(t1, t2, end=", ")
for i in range(3, n + 1):
next_term = t1 + t2
print(next_term, end=", " if i < n else "\n")
t1, t2 = t2, next_term
def main():
print("====================================")
print(" Fibonacci Sequence Generator ")
print("====================================")
try:
n = int(input("Enter the number of terms you want to generate: "))
if n <= 0:
print("\nPlease enter a positive integer.\n")
else:
generate_fibonacci(n)
except ValueError:
print("\nInvalid input! Please enter an integer.\n")
print("====================================")
print(" Program Ended ")
print("====================================")
if __name__ == "__main__":
main()