Home > other >  Python beginner programming problem sets
Python beginner programming problem sets

Time:11-19

Beginner novice, meets the arithmetic square root logic to write not to come out! Can change the code, please help!

CodePudding user response:

Are you sure is the python language?

CodePudding user response:

Completion by the implementation of the arithmetic square root, the x value cannot be changed! The completion variable, and use Python to write out!

CodePudding user response:

So don't know if it can, reference
 # precondition: x & gt;=0 
Def SQRT (x) :
Assert (x & gt;=0)
Y=0
R=x - y * y
While r & gt; Y + 1=2 * :
Y +=1
R=x - y * y
Assert (y * y & lt;=x <(y + 1) * (y + 1))
Return y
# postcondition: y ^ 2 & lt;=x <(y + 1) ^ 2

If __name__=="__main__" :
X=123.456
Y=SQRT (x)
Print (f '{} y ^ 2 & lt;={x} & lt; {y + 1} ^ 2 ')
  • Related