
November 5th, 2012, 07:11 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 7
Time spent in forums: 4 h 23 m 15 sec
Reputation Power: 0
|
|
|
While loops
python novice.
Trying to link two functions with embedded while loops. Each function (base(i) and sqform(base) works on its own. But when linked I can't get it to work.
Attempting to get the following output:
ex: i = 4
4.0, 2.0, 2.0
3.0, 1.73, 1.73
2.0, 1.41, 1.41
1.0, 1.0, 1.0
currently only getting:
4.0, 2.0, 2.0
using version 2.7.3 writing gedit
Code:
from math import *
def base(i):
base = i
while base > 0:
sqform(base)
base = base - 1
def sqform(base):
a = base
x = base - 1
y = (x + a/x)/2
while y != x:
x = y
y = (x + a/x)/2
else:
print float(a), float(x), float(sqrt(a))
i = int(raw_input('Enter number.\n'))
base(i)
|