Tag Archive: Loop

  • How to create the Fibonacci Sequence in Python

    This blog post will go through how to create the famous Fibonacci sequence in Python. Each number in the Fibonacci sequence is the sum of the previous two terms. The sequence starts: 0, 1, 1, 2, 3, 5, 8, 13, … and carries on infinitely. The Python code I used is: The first two terms are entered into our list, then we specify the number of terms wanted in our sequence. Next, we loop through from 2 to the number of terms we wanted appending…

    » Read more
  • Join 2 Python lists together using nested loops

    In this blog post I will show you how to join two 2D Python lists together. The code is in the screenshot below. Lines 1 – 2 are two lists that are going to be joined, line 3 is an empty list where the output will be appended to. Lines 4 – 5 are two loops (one nested inside the other) which cycle through the records in both lists, line 6 checks whether the first items (index 0) in the two records from each list that are currently i…

    » Read more
  • How to delay a Python loop

    In this blog post, I will run through 3 different ways to execute a delayed Python loop. In these examples, we will aim to run the loop once every minute.To show the delay, we will print out the current datetime using the datetime module. 1 – SleepThe sleep function from Python’s time module pauses the Python execution by the number of seconds inputted. The example below pauses the script for 60 seconds. The above script has a 60 second…

    » Read more