标签:
一、求算术平方根
a=0 x=int(raw_input(‘Enter a number:‘)) if x >= 0: while a*a < x: a = a + 1 if a*a != x: print x,‘is not a perfect square‘ else: print a else: print x,‘is a negative number‘
二、求约数
方法一:
divisor = [ ] x=int(raw_input(‘Enter a number:‘)) i=1 while i<=x: if x%i ==0: divisor.append(i) i = i +1 print ‘divisor:‘,divisor
方法二:
divisor = [ ] x=int(raw_input(‘Enter a number:‘)) for i in range(1,x+1): if x%i ==0: divisor.append(i) # 此行也可以换成 divisor = divisor + [i] print ‘divisor:‘,divisor
标签:
原文地址:http://www.cnblogs.com/glorywu/p/Python-Square-Divisor.html