You are on page 1of 2

1

How to compute the square root of a given number x with python?


Departamento de Ingenier a El ectrica, Electr onica y Computaci on Universidad Nacional De Colombia - Sede Manizales David Alfonso Berrio Perdomo 811006 Agosto 6 de 2012

abstractin this document describes the steps done to create an algorithm that resolve a given problem (Compute the square root of a number).The algorithm was programed in python 3.2.[1]

I. I NTRODUCTION python is a script language in which we can encode using linear programming, structured and objectoriented.[2] Python can be used to develop specic applications as web applications, mobile or non-visual applications.python can be to design an application that calculates the square root of a number, this will be described in the following sections of this document II.

>>print (g) >>else: >>while abs((g*g)-x)tol: >>g=((g+(x/g))/2) #Show answer >>print (The root of the number is:) >>print (g) >>input()

IV. T ESTING (C ONVERGENCE AND TOLERANCE )

OBJECTIVES

apply basic concepts of python to solve a given problem Create an algorithm that calculates the square root of a number Prove the convergence and accuracy of the data produced by the application III. A LGORITHM D ESCRIPTION
Figure 1. number(169),tolerance(0),square root(13)

#Name Program >>print (Compute the square root of a given number x) #The user enters the number to calculate >>print (Enters the number to calculate) >>x=oat(input()) #Enters Measurement error >>print (enters tolerance) >>tol=oat(input()) #generation of a random integer g within a set range [1,9] >>import random >>g=random.randrange(1, 9) #compute the square root >>if abs((g*g)-x)=tol: >>print (The root of the number is:)

Figure 2.

number(145),tolerance(0.0012),square root(12.0416)

Figure 3.

number(23.53),tolerance(0.0001),square root(4.85078)

V.

CONCLUSIONS

python can be a powerful tool for computational problem solving The convergence can be guaranteed for almost all numbers The accuracy of the result depends on the tolerance that the user enters R EFERENCES

[1] http://www.python.org/ [2] http://pythonya.appspot.com/detalleconceptodeta=Introducci on

You might also like