我有一个用户输入'n',我找到了平方根。我知道的是math.sqrt(n),但我需要让程序继续找到平方根,直到它小于2.同时返回给用户程序运行多少次以找到小于2的根,使用计数器。我正在使用python。使用Python的平方根循环有问题
到目前为止:
import math
root = 0
n = input('Enter a number greater than 2 for its root: ')
square_root = math.sqrt(n)
print 'The square root of', n, 'is', square_root
keep_going = 'y'
while keep_going == 'y':
while math.sqrt(n) > 2:
root = root + 1
如果这是家庭作业,请将其标记为此类。 – Oddthinking 2011-03-29 02:46:40
你做了什么? – 2011-03-29 02:47:44
你应该把你的代码放到原来的问题中。这将使其可读性更强,特别是在使用缩进的情况下。 – JoshAdel 2011-03-29 03:17:20