首页 > 其他 > 详细

提高级

时间:2018-10-25 22:32:20      阅读:172      评论:0      收藏:0      [点我收藏+]
#二分开方
x = 2
low = 0.0
high = x
guess = (low+high)/2
while abs(guess**2-x) >1e-4:
    if guess**2 >x:
        high = guess
    else:
        low = guess
    guess = (low +high) /2
print (guess)


1.4141845703125
#局部变量,全局变量
x = 1
def f():
    x = 2
    print(x)
f()
print(x)

2
1
 1 x = 1
 2 def f():
 3     global x#x为全局变量
 4     x = x+1
 5     print(x)
 6 f()
 7 print(x)
 8 
 9 2
10 2

 

提高级

原文:https://www.cnblogs.com/tingtin/p/9853336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!