class Tiao(object):
def __init__(self):
self.obj1 = datetime.timedelta(seconds=1)
self.var = '%H:%M:%S'
def add(self, var):
a = datetime.datetime.strptime(var, self.var)
b = a + self.obj1
return str(b.strftime(self.var))
def str_time(self, var3):
a, b, c = [int(i) for i in var3.split(":")]
a *= 3600
b *= 60
return a + b + c
def yuan(self, var1, var2):
"""
计算 百分比
:param var1: 现在时间
:param var2: 总时间
"""
var1 = self.str_time(var1)
var2 = self.str_time(var2)
return '{:.2%}'.format(var1/var2)
def zhanshi(var):
a = Tiao()
b = "00:00:00"
while True:
if var == b:
break
b = a.add(b)
print('\r%s/%s (%s)' % (b, var, a.yuan(b, var)), end='')
time.sleep(1)
zhanshi("00:25:37")
import random
random.seed(180)
hit = 0.0 #表示随机点在圆内的次数
#请将代码补充完整
for i in range(10000):
x=random.random()
y=random.random()
if x**2+y**2<1:
hit+=1.0
pi=4*hit/10000.0
print("{:.2f}".format(pi))
import random
random.seed(180)
hit = 0.0 #表示随机点在圆内的次数
#请将代码补充完整
for i in range(10000):
x=random.random()
y=random.random()
if x**2+y**2<1:
hit+=1.0
pi=4*hit/10000.0
print("{:.2f}".format(pi))