Answered step by step
Verified Expert Solution
Question
1 Approved Answer
, * * Instructions: * * , 1 . Complete the tasks below by editing / adding the code in
Instructions: Complete the tasks below by editingadding the code in the code cells directly below each question. 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.acza "celltype": "markdown", id: aeaf "metadata": "source": ## Question : debugging 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 the output should be: "Fibonacci sequence of terms: "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." "celltype": "code", "executioncount": null, id: eac "metadata": "outputs": "source": "numterms inputEnter the number of terms: t t "counter # counter for checking when to stop if numterms printNo terms number is not positive "else: while counter numterms: printFibonacci sequence of numterms, terms: if counter numterms : # the last term printt else: printt end nextterm t t # update values t t t nextterm" "celltype": "markdown", id: b "metadata": "source": ## Question : number of characters and words marks "Write code to input a sentence from the user and output the number of characters in the sentence as well as the estimated number of words in the sentence excluding leading or trailing spacesHint: You can estimate the number of words by counting the number of spaces in the sentence. "celltype": "code", "executioncount": null, id: f "metadata": "outputs": "source": "celltype": "markdown", id: aa "metadata": "source": ## Question : Ackley's function marks "Write code to input two numbers from the user x and x and then print out the result of the following fuction known as Ackley's function You can test your code using the following test cases: f $approx$ and f $approx$ Hint: In Python, trigonometric functions such as cos and sin are defined in the math package. $fxxtextrmexpbigsqrtx xbigtextrmexpcospi xcospi xtextrmexp$ "celltype": "code", "executioncount": null, id: "edcc "metadata": "outputs": "source": "celltype": "markdown", id: abcc "metadata": "source":
Instructions:
Complete the tasks below by editingadding the code in the code cells directly below each question.
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.acza
"celltype": "markdown",
id: aeaf
"metadata":
"source":
## Question : debugging 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 the output should be:
"Fibonacci sequence of terms:
"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."
"celltype": "code",
"executioncount": null,
id: eac
"metadata":
"outputs":
"source":
"numterms inputEnter the number of terms:
t
t
"counter # counter for checking when to stop
if numterms
printNo terms number is not positive
"else:
while counter numterms:
printFibonacci sequence of numterms, terms:
if counter numterms : # the last term
printt
else:
printt end
nextterm t t
# update values
t t
t nextterm"
"celltype": "markdown",
id: b
"metadata":
"source":
## Question : number of characters and words marks
"Write code to input a sentence from the user and output the number of characters in the sentence as well as the estimated number of words in the sentence excluding leading or trailing spacesHint: You can estimate the number of words by counting the number of spaces in the sentence.
"celltype": "code",
"executioncount": null,
id: f
"metadata":
"outputs":
"source":
"celltype": "markdown",
id: aa
"metadata":
"source":
## Question : Ackley's function marks
"Write code to input two numbers from the user x and x and then print out the result of the following fuction known as Ackley's function You can test your code using the following test cases: f $approx$ and f $approx$ Hint: In Python, trigonometric functions such as cos and sin are defined in the math package.
$fxxtextrmexpbigsqrtx xbigtextrmexpcospi xcospi xtextrmexp$
"celltype": "code",
"executioncount": null,
id: "edcc
"metadata":
"outputs":
"source":
"celltype": "markdown",
id: abcc
"metadata":
"source":
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started