subject

Package Newton’s method for approximating square roots (Case Study: Approximating Square Roots) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The program should also include a main function that allows the user to compute the square roots of inputs from the user and python's estimate of its square roots until the enter/return key is pressed. My code:

import math

tolerance = 0.00001
def newton(x):
estimate = 1.0
while True:
estimate = (estimate + x/estimate) /2
difference = abs(x - estimate**2)
if difference <= tolerance:
break
return estimate

def main():
while True:
x = input("Enter a positive number or enter/return to quit: ")
if x==" ":
break
x = float(x)

print("The program's estimate of the square root of",x,"is", round(newtown(x),2))
print("Python's estimate is:",math. sqrt(x))

main()

it keeps coming up with a syntax error --invalid syntax for line 23 except:

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 17:00
Which process would best represent the opposite of exhausting air from a system?
Answers: 2
question
Computers and Technology, 23.06.2019 17:10
Ac++an of of pi. in , pi is by : pi = 4 – 4/3 + 4/5 – 4/7 + 4/9 - 4/11 + 4/13 - 4/15 + 4/17 . ., to pi (9 ). , if 5 to pi,be as : pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 = 4 – 1. + 0.8 - 0. + 0. = 3.. atoofbe to pi?
Answers: 2
question
Computers and Technology, 23.06.2019 19:50
Which feature is selected to practice and save the timing of a presentation
Answers: 1
question
Computers and Technology, 24.06.2019 08:00
Can someone work out the answer as it comes up in one of my computer science exams and i don't understand the cryptovariables
Answers: 1
You know the right answer?
Package Newton’s method for approximating square roots (Case Study: Approximating Square Roots) in a...
Questions
question
Physics, 16.01.2021 06:40
question
Health, 16.01.2021 06:40
question
Mathematics, 16.01.2021 06:40
question
English, 16.01.2021 06:40
Questions on the website: 13722367