-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha03.py
More file actions
38 lines (24 loc) · 680 Bytes
/
a03.py
File metadata and controls
38 lines (24 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## IMPORTS GO HERE
## END OF IMPORTS
#### YOUR CODE FOR sqrt() FUNCTION GOES HERE ####
def sqrt(x,guess=0.1):
if x==0:
return None
if (guess * guess)-x<0.00001 and (guess * guess)-x > 0:
return guess
else:
new_guess =improve_guess(guess,x)
return sqrt(x,new_guess)
#### End OF MARKER
#### YOUR CODE FOR average() FUNCTION GOES HERE ####
def average(a,b):
average =(a + b)/2.0
return average
#### End OF MARKER
#### YOUR CODE FOR improve_guess() FUNCTION GOES HERE ####
def improve_guess(guess,x):
new_guess=average(guess,x/guess)
return new_guess
#### End OF MARKER
if __name__ == '__main__':
print sqrt(36)