首页 > 代码库 > 作业选择

作业选择

BMI
height,weight=eval(input("输入身高和体重:"))
bmi=weight/pow(height,2)
print("BMI数值为:{.2f}",format(bmi))
who,dom="",""
if bmi<18.5:
who="偏瘦"
elif bmi<25:
who="正常"
elif bmi<30:
who="偏胖"
else:
who="肥胖"
if bmi<18.5:
dom="偏瘦"
elif bmi<25:
dom="正常"
elif bmi<30:
dom="偏胖"
else:
dom="肥胖"

print("BMI指标为:国际‘{0}’,国内‘{1}’",format(who))

from random import random
from math import sqrt
from time import clock
darts = 10000
hits =0.0
clock()
for i in range(1,darts+1):
x,y = random(),random
dist=sqrt(x * 2+y * 2)
if dist <=1.0:
hits=hits+1
pi=4*(hits/darts)
print("PI值是{}.",format(pi))
print("运行时间是:{:5.5}s",format(clock()))

作业选择