## Question 1: debugging (9 marks) The following code is
supposed to print out the Fibonacci sequence up to the number of
terms specified by the user. For example, if the user enters 10,
the output should be: Fibonacci sequence of 10 terms:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34 However, the program contains a
number of errors. Your task is to fix the code until it works
correctly.
For each error that you find in the program, add a comment to
explain the error.
num_terms = input("Enter the number of terms: ")
t1 = 0
t2 = 1
counter = 1 # counter for checking when to stop
if num_terms <= 0
print("No terms - number is not positive")
else:
while counter < num_terms:
print("Fibonacci sequence of",
num_terms, " terms:")
if (counter = num_terms - 1): # the
last term
print(t1)
else:
print(t1, end = ",
")
next_term = t1 + t2
# update values
t1 = t2
t2 = next_term
## Question 1: debugging (9 marks) The following code is supposed to print out the Fibonacci sequence up to the number o
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am