Python Program of Fibonacci Series
Hello, friends, it's time to do some digital and tricky to gain lots of marks in the additional subject of class 12th that is Computer Science.
Today I want to give you a very important 3marks or 4 marks question for class 12th who is new in the python programming.
I know that it is tough to know which program or questions in the new programming language that is new for all the students even for teachers.
So, if you want the critical program, then stay tuned with this article.
What is Programming:-
Programming is a talent of any web or a software developer. It is essential coding or a language that connect the programmer, user and a machine, without programming language, there is no internet, no social media, nothing that we are doing in our mobile or on the internet.
The programming language is a language that interacts the user and machine in user-readable and graphical views to make the interaction between the user and the computer.
The programmer is the way by which it can create the machine or any software to interact with the users.
Python is one of the programming languages.
Why Python Introduce as a programming language:-
Python is a straightforward and easy learning programming language by any of the students of class 6th also.
Python programming language is the most straightforward language and easy syntax than another problematic programming language.
My opinion is that Python is the best programming language for beginners.
What is the Fibonacci Series:-
Fibonacci Series is the series start with the fixed digit of 0 and 1.
It is the series that is made in the python programming language or any language with different syntax or function.
Today I want to give you the Fibonacci Series by using functions.
What is the Fibonacci number:-
It is the number that is after the fixed digit of the Fibonacci Series that is 0 and 1.
It is a number after the number of that series.
Fibonacci Series using functions:-
# -*- coding: utf-8 -*-
"""
@author: Mohit Gupta
"""
def FibonacciSeries (parNoOfTerms):
''' Program to display the Fibonacci sequence up to n-th term'''
# first two terms of the series
n1, n2 = 0, 1
count = 0
# Initialise the Empty List
myFibonacciSeriesList = []
# Validation check: number of terms should be a positive integer
# Return an empty list if the no is not positive
if parNoOfTerms <= 0:
print("Error: Please enter a positive integer")
return myFibonacciSeriesList
elif parNoOfTerms == 1:
# If the no is 1 print the list
myFibonacciSeriesList.append(n1)
return myFibonacciSeriesList
elif parNoOfTerms > 1:
myFibonacciSeriesList.append(n1)
#initialise first no as 0
myFibonacciSeriesList.append(n2)
#Initialise Second no as 1
count = 2
while count < parNoOfTerms:
# Calculate value of Next No
nth = n1 + n2
n1 = n2
n2 = nth
myFibonacciSeriesList.append(n2)
# Update Counter
count += 1
# End of While Loop
return myFibonacciSeriesList
# End of While loop
# End of elif
# End of Function Fibonacci
print ("\n", "Welcome to Fibonacci Series Program".center(100,'-'))
nterms = int(input("How many terms? "))
print("Fibonacci sequence upto first",nterms,"terms:")
print (FibonacciSeries(nterms))
print ("\n", "Thank you for using Fibonacci Series Program".center(100,'-'))
Thanks for reading this program
No comments:
Post a Comment