A201 Introduction to Programming 1

A201 Lab 5

Date: Tuesday, September 19, 2023.
Due Date: Tuesday, September 26, 2023.

Goal: to use for loops in Python.

In this lab, we will be working on the for loops with a range in Python.

Open the Python Idle and create a new file called lab5.py. Add your name and the lab number as a comment at the top.

Ex. 1. For loops

Write a for loop displaying each of the following sequence of numbers, where the upper bound mentioned should be included in all of them:

Print a message before each sequence explaining what will be printed.

Ex. 2. Fibonacci sequence

The Fibonacci sequence is a sequence of number where each new one is the sum of the previous two. For example, the first 10 Fibonacci numbers are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

Write a program that prints out the first 15 Fibonacci numbers. Use a for loop with a range for this. Before the loop, declare two variables, f1 and f2, initialized with 0 and 1. Then in the loop, do the following:

f = f1 + f2
f1 = f2
f2 = f
print(f)

Test the program to make sure it works.

Lab Submission

Upload the file lab5.py in Canvas, Assignments, Homework 5. You can wait until you finish the homework to upload both files at the same time.