2020-10-30

                               江西财经大学二学位python第5次实验

# 5.1

def interBMI(height , weight):
    BMI = weight/(height * height)
    if BMI < 18.5:
        result = "偏瘦"
    elif 18.5<= BMI < 25:
        result = "正常"
    elif 25 <= BMI <30:
        result = "偏胖"
    else :
        result = "肥胖"
    print("国际:%s" % result )

 

def domBMI(height , weight):
    BMI = weight/(height * height)
    if BMI < 18.5:
        result = "偏瘦"
    elif 18.5<= BMI < 24:
        result = "正常"
    elif 24 <= BMI <28:
        result = "偏胖"
    else :
        result = "肥胖"
    print("国内:%s" % result)

height, weight = eval(input("请输入身高(m)、体重(kg):"))
BMI = weight/(height * height)
print("BMI值为:{:.2f}".format(BMI))
interBMI(height , weight)
domBMI(height , weight)

 

# 5.2

 

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

print("BMI指标为:国际'{0}',国内'{1}'".format(who,dom))

# 6.1

from random import random
from math import sqrt
from time import process_time
DARTS = 1000
hits = 0.0
process_time()   #process_time()函数第一次调用时,开始记时,第二次调用返回运行时间
for i in range(1,1+DARTS):
    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("运行时间:{:.5f} s".format(process_time()))

# 4.4

from random import*
Num = randint(0,100)
UsrNum = eval(input("请输入你猜的数字:"))
counter = 1
while(Num != UsrNum):
    if(UsrNum>Num):
        print("遗憾,太大了")
        counter = counter + 1
    else:
        print("遗憾,太小了")
        counter = counter + 1
    UsrNum = eval(input("请输入你猜的数字:"))
print("预测了%s次" % counter )

#4.2

str = input("请输入一行字符:")
alpha,num,space,other=0,0,0,0
for i in str:
    if i.isalpha():
        alpha+=1
    elif i.isdigit():
        num+=1
    elif i.isspace():
        space+=1
    else:
        other+=1
print('英文字符数{},数字字符数{},空格字符数{},其他字符数{}'.format(alpha,num,space,other))

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值