Discuss / Python / 第一次交作业

第一次交作业

Topic source

name=input('请输入你的姓名:') height=input('请输入你的身高(cm):') weight=input('请输入你的体重(kg):') a=int (height) b=int (weight) print ('%s,你的身高是%d厘米,体重是%d公斤。\n你的体重状况为:' %(name,a,b)) bmi=b/(a/100)**2 if bmi<18.5: print('过轻') elif bmi<=25: print( '正常') elif bmi<=28: print('过重') elif bmi<=32: print('肥胖') elif bmi>32: print('严重肥胖')

no0110

#2 Created at ... [Delete] [Delete and Lock User]

答案# -- coding: utf-8 --

height = 1.75 weight = 80.5 bmi = weight/(height*height) if bmi > 32: print('严重肥胖') elif bmi > 28: print('肥胖') elif bmi > 25: print('过重') elif bmi > 18.5: print('正常') else: print('过轻')

方糖米菲

#3 Created at ... [Delete] [Delete and Lock User]

一楼我觉得int()应该用float()代替,因为如果用int()的话,输入的体重或者身高不是整数会报错。


  • 1

Reply