
- What's Fibonacci
- Practice Loops
- Practice Lists
Fibonacci Sequence
Let's practice working with Loops!
I want you to create a simple script to calculate the sequence of Fibonacci numbers. And don't worry, it has a very simple logic.
It start with 0 and 1, and each next numer is a sum of the previous 2 numbers. So here are the first 10 numers of Fibonacci Sequence:
Before we begin, I want you to try it on your own.
Spend 5-15 minutes writing code to create these numbers. Even if you don't know how to do it yet, just give it a try. The answer might pop in your head as you begin to code.
Define first 2 numbers (
a=0,b=1)Create a loop with range (
for i in range(n))And then define logic to print Fibonacci Sequence
Bonus point: Write the number name in the beginning (Thousand, Million, Billion, Trillion...)
Ready? Set. Code!
Now Let's Code Together
So let's start with the basics.
Define your first numbers and create a simple for-loop with range(). 
Then since next number is the sum of the previous one we'll sum it up (c = a+b )
Keep in mind that we want to start seeing numbers from 0 in the console. So we should print a variable instead of c. And then make sure that we shift values for a,b variables.
Here's the code:
And we get to very large number really quick:


Now, it's really hard for human eye to understand this soup of numbers. So it would be great if we could add a thousands-separator (or whatever it's called) every 3 digits.
Special String Formatting
When we use f-string we can use special symbols inside our placeholder to format how it will be displayed in text. It's a bit tricky, but once you know it's possible, it's easy to get the answer with Chat GPT. But here are the basics:
Here's the table of various controls we could use:
In our case we'd want to use d to specify that it's a Decimal Integer. And we'll use , to insert comma every 3 digits for integer presentation.
Here's how our print line would look like:
And thanks to this line here's how our results look in the console:
Way better, but we still not sure what are these super large numbers.
So let's add it as the next step.
Calculate Large Number Name
First of all we need to create a container of Large Number Names. We could use dictionary, but since it will be used in the same order, we can just define it as a list.
Next, we need to choose the right one based on our number. And it's actually very simple to do, because we already have commas , in our numbers, so we just need to calculate how many commas we have and it will be the same index of a number. Lucky us, huh?
So here's the code to:
Count commas
Get the right name
Print it before number
And just like that we start to get results like this:
Now it's looking way better, Great Job!

Final Code
Congratulations, you've reached the end. 
Let's put it all together in a single script to avoid any confusion.
I hope that you tried to create a Sequence of Fibonacci Numbers on your own first.
But if not, at least follow along the lesson and try to code along side me. It will really help you get into a habit of writing the code yourself. Even if it looks simple, you need to get the reps in.
That's the only way to get good at python - YOU HAVE TO CODE YOURSELF TOO.
Sposored by LearnRevitAPI.com





