import os
# make 制作 dir文件夹
x = 0
while x < 100:
os.remove(str(x))
x += 1
import os
# os.mkdir(r"C:\Users\jrcode01\Desktop\pubg")
for x in range(10000):
os.mkdir(r"C:\Users\jrcode01\Desktop\pubg\%d"%x)
import time as t
def pi(n):
p = 10 ** (n + 10) # 准备初始整数,先多乘 k 个 0,以增加精度,最后再去掉,这里我取 k=10
a = p * 16 // 5 # 第一项的前半部分
b = p * 4 // -239 # 第一项的后半部分
f = a + b # 第一项的值
p = f # π
j = 3
while abs(f): # 当|f|=0后计算π的值就不会再改变了
a //= -25 # 第n项的前半部分
b //= -57121 # 第n项的后半部分
f = (a + b) // j
p += f
j += 2
return p // 10**10 # 去掉 k 位,k=10
t1 = t.time()
s = str(pi(100000))
print(s)
print(s.find("29515"))
t2 = t.time()
print(t2-t1)
# open write read
# f = open("yzl.txt","w")
# f.write('12345')
# f.close()
f = open('yzl.txt','r')
c = f.read()
print(c)
f.close()
Bob - 文件的读取和写入
猜你喜欢
转载自blog.csdn.net/houlaos/article/details/106733428
今日推荐
周排行