Book Image

Parallel Programming with Python

Book Image

Parallel Programming with Python

Overview of this book

Table of Contents (16 chapters)
Parallel Programming with Python
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Obtaining the highest Fibonacci value for multiple inputs


It is known that the Fibonacci sequence is defined as follows:

In practical terms, calculating the Fibonacci value for the terms 0 to 10, the result would be 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and 55.

An example of Python code to calculate Fibonacci returning the highest value using the iterative method is as follows:

def fibonacci(input):
    a, b = 0, 1
    foritem in range(input):
        a, b = b, a + b
    return a

The Fibonacci function calculates the highest Fibonacci value for a specific piece of input data. Let us picture a hypothetical scenario in which it is necessary to calculate Fibonacci values, and this website will receive several inputs from a user. Suppose the user provides an array of values as input, so making these calculations sequentially would be interesting. But, what if 1 million users are connected at the same time to make requests? In this case, some users would have to wait for quite a long time until they...