Question: , * * Instructions: * * , 1 . Complete the tasks below by editing / adding the code in

"
",
"**Instructions:**
",
"1. Complete the tasks below by editing/adding the code in the code cells directly below each question.
",
"2. Submit your completed .ipynb file on the module website under the appropriate link.
",
"
",
"For any queries about this assignment, email Katherine Malan at malankm@unisa.ac.za"
]
},
{
"cell_type": "markdown",
"id": "a90e88af",
"metadata": {},
"source": [
"## 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."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e9a221c9",
"metadata": {},
"outputs": [],
"source": [
"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"
]
},
{
"cell_type": "markdown",
"id": "48b09078",
"metadata": {},
"source": [

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!