n=int(input("How many terms you want to go? ")) n1, n2 = 0, 1 count = 0 if n <= 0: # check if the number of terms is valid print("Please enter a positive number") elif n == 1: print("Fibonacci sequence upto",n,":") print(n1) else: print("Fibonacci series:") while count < n: print(n1) nth = n1 + n2 # update values n1 = n2 n2 = nth count += 1 Output 1: How many terms you want to go? 9 Fibonacci series: 0 1 1 2 3 5 8 13 21 Output 2: How many terms you want to go? -2 Please enter a positive number
इन्हें भी देखें।
- while loop
- for loop
- nested loops
- loop control statements (Break, Continue, Pass)
- if statement
- if-else statement
- if-elif statement
- nested if statement
- range() function
- keywords
- Identifiers (names)
- Literals
- Operators
- punctuatorts
Python Programs के लिये यहाँ click करें।