Discuss / Python / 有几个问题

有几个问题

Topic source

diska本尊

#1 Created at ... [Delete] [Delete and Lock User]
#计算体重
sg1 = int(input('你的身高:单位厘米'))
sg2 = sg1/100
tz = int(input('你的体重:单位千克'))
bj = ('%d' % (tz / (sg2*sg2)))

if int(bj) > 32:
    print('太胖了')
elif int(bj) > 28:
    print('很胖')
elif int(bj) > 25:
    print('有点胖')
elif int(bj) >= 18.5:
    print('正常')
else:
    print('不在范围内')

不用int的话他好像当成字符串了。。为啥嘞?

diska本尊

#2 Created at ... [Delete] [Delete and Lock User]
#计算体重
sg1 = float(input('你的身高:单位厘米'))
#sg2 = sg1/100
tz = int(input('你的体重:单位千克'))
bj = ('%d' % (tz / (sg1*sg1)))

if int(bj) > 32:
    print('太胖了')
elif int(bj) > 28:
    print('很胖')
elif int(bj) > 25:
    print('有点胖')
elif float(bj) >= 18.5:
    print('正常')
else:
    print('不在范围内')

把sg1的int和最后一个比较18.5的换成float,这下子就可以了。


  • 1

Reply