🚧Summaries For Lessons 24+ Are Still Work In Progress!

“Whoever is patient has great understanding…" Proverbs 14:29

Exercise: Fibonacci Seq with a Loop

Description here...

Exercise: Fibonacci Seq with a Loop

Description here...

Exercise: Fibonacci Seq with a Loop

Description here...

- 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!

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

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:

#🔢 Define First Numbers
a = 0
b = 1

#🔁 Create For-Loop
for i in range(100):
    print(a)

    #➡️ Shift Numbers
    c = a+b
    a = b
    b = c
#🔢 Define First Numbers
a = 0
b = 1

#🔁 Create For-Loop
for i in range(100):
    print(a)

    #➡️ Shift Numbers
    c = a+b
    a = b
    b = c
#🔢 Define First Numbers
a = 0
b = 1

#🔁 Create For-Loop
for i in range(100):
    print(a)

    #➡️ Shift Numbers
    c = a+b
    a = b
    b = c

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:

print(f'{a:,d}')
print(f'{a:,d}')
print(f'{a:,d}')

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.

#📃 Large Number Names
number_names = [
    "",         # 10^3
    "thousand",         # 10^3
    "million",          # 10^6
    "billion",          # 10^9
    "trillion",         # 10^12
    "quadrillion",      # 10^15
    "quintillion",      # 10^18
    "sextillion",       # 10^21
    "septillion",       # 10^24
    "octillion",        # 10^27
    "nonillion",        # 10^30
    "decillion",        # 10^33
    "Bajillion"         # 10^~ (I made this up...)
]
#📃 Large Number Names
number_names = [
    "",         # 10^3
    "thousand",         # 10^3
    "million",          # 10^6
    "billion",          # 10^9
    "trillion",         # 10^12
    "quadrillion",      # 10^15
    "quintillion",      # 10^18
    "sextillion",       # 10^21
    "septillion",       # 10^24
    "octillion",        # 10^27
    "nonillion",        # 10^30
    "decillion",        # 10^33
    "Bajillion"         # 10^~ (I made this up...)
]
#📃 Large Number Names
number_names = [
    "",         # 10^3
    "thousand",         # 10^3
    "million",          # 10^6
    "billion",          # 10^9
    "trillion",         # 10^12
    "quadrillion",      # 10^15
    "quintillion",      # 10^18
    "sextillion",       # 10^21
    "septillion",       # 10^24
    "octillion",        # 10^27
    "nonillion",        # 10^30
    "decillion",        # 10^33
    "Bajillion"         # 10^~ (I made this up...)
]

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

num          = f'{a:,d}'
count_commas = num.count(',')
large_num    = number_names[count_commas]
print(large_num, num)
num          = f'{a:,d}'
count_commas = num.count(',')
large_num    = number_names[count_commas]
print(large_num, num)
num          = f'{a:,d}'
count_commas = num.count(',')
large_num    = number_names[count_commas]
print(large_num, num)

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.

#🧮 Calculate Fibonacci Sequence 0 1 1 2 3 5 8 13 21 34

#📃 Large Number Names
number_names = [
    "",         # 10^3
    "thousand",         # 10^3
    "million",          # 10^6
    "billion",          # 10^9
    "trillion",         # 10^12
    "quadrillion",      # 10^15
    "quintillion",      # 10^18
    "sextillion",       # 10^21
    "septillion",       # 10^24
    "octillion",        # 10^27
    "nonillion",        # 10^30
    "decillion",        # 10^33
    "Bajillion"         # 10^~ (I made this up...)
]

a = 0
b = 1

for i in range(175):
    num          = f'{a:,d}'
    count_commas = num.count(',')
    large_num    = number_names[count_commas]
    print(large_num, num)

    c = a + b
    a = b
    b = c
#🧮 Calculate Fibonacci Sequence 0 1 1 2 3 5 8 13 21 34

#📃 Large Number Names
number_names = [
    "",         # 10^3
    "thousand",         # 10^3
    "million",          # 10^6
    "billion",          # 10^9
    "trillion",         # 10^12
    "quadrillion",      # 10^15
    "quintillion",      # 10^18
    "sextillion",       # 10^21
    "septillion",       # 10^24
    "octillion",        # 10^27
    "nonillion",        # 10^30
    "decillion",        # 10^33
    "Bajillion"         # 10^~ (I made this up...)
]

a = 0
b = 1

for i in range(175):
    num          = f'{a:,d}'
    count_commas = num.count(',')
    large_num    = number_names[count_commas]
    print(large_num, num)

    c = a + b
    a = b
    b = c
#🧮 Calculate Fibonacci Sequence 0 1 1 2 3 5 8 13 21 34

#📃 Large Number Names
number_names = [
    "",         # 10^3
    "thousand",         # 10^3
    "million",          # 10^6
    "billion",          # 10^9
    "trillion",         # 10^12
    "quadrillion",      # 10^15
    "quintillion",      # 10^18
    "sextillion",       # 10^21
    "septillion",       # 10^24
    "octillion",        # 10^27
    "nonillion",        # 10^30
    "decillion",        # 10^33
    "Bajillion"         # 10^~ (I made this up...)
]

a = 0
b = 1

for i in range(175):
    num          = f'{a:,d}'
    count_commas = num.count(',')
    large_num    = number_names[count_commas]
    print(large_num, num)

    c = a + b
    a = b
    b = c

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

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.

⌨️ Happy Coding!

⌨️ Happy Coding!

⌨️ Happy Coding!

If you have any questions, leave them in the YouTube Comments.

If you have any questions, leave them in the YouTube Comments.

If you have any questions, leave them in the YouTube Comments.

Have a Question?

Have a Question?

Have a Question?

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

PS. Python can change your career and how you think about problems.
Be Careful 🙂

PS. Python can change your career and how you think about problems.
Be Careful 🙂

PS. Python can change your career and how you think about problems.
Be Careful 🙂

Sposored by LearnRevitAPI.com