%:返回两数相除后的余数
eg:60%60->0
elif: else if
Print常用输出:
print('字符串 ' + 字段名 + '字符串')
print(A, end=" "):输出后面加空格
Practice
import math
def sequence(n):
print
while n<=9:
print(float(n),end=" ")
print(sqrts(n),end=" ")
print(math.sqrt(n),end=" ")
print(abs(math.sqrt(n)-sqrts(n)))
n=n+1
# print(sqrts(n),math.sqrt(n),end=" ")
def sqrts(a):
x=6
while True:
y = (x + a/x) / 2
if y==x:
break
x=y
return x
输出结果:
1.0 1.0 1.0 0.0
2.0 1.414213562373095 1.4142135623730951 2.220446049250313e-16
3.0 1.7320508075688772 1.7320508075688772 0.0
4.0 2.0 2.0 0.0
5.0 2.23606797749979 2.23606797749979 0.0
6.0 2.449489742783178 2.449489742783178 0.0
7.0 2.6457513110645907 2.6457513110645907 0.0
8.0 2.82842712474619 2.8284271247461903 4.440892098500626e-16
9.0 3.0 3.0 0.0
网友评论