交作业,自己输姓名体重,身高
Topic source不知道else和elif不能同用,提交的时候改了一下,,,,
下面是修改的,测试可以运行
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
name=input('please enter your name:')
h=int(input('please enter your Height(cm):'))
w=int(input('please enter your Weight(kg):'))
h1=h/100
b1=h1*h1
b2=w/b1
print('bmi=%.2f'%(b2))
if b2<18.5:
print('hello,%s,your Height is:%s,your Weightis:%s,BMI:%.2f,so light'%(name,h,w,b2))
elif b2<25:
print('hello,%s,your Height is:%s,your Weightis:%s,BMI:%.2f,nomal'%(name,h,w,b2))
elif b2<28:
print('hello,%s,your Height is:%s,your Weightis:%s,BMI:%.2f,strong'%(name,h,w,b2))
elif b2<32:
print('hello,%s,your Height is:%s,your Weightis:%s,BMI:%.2f,obesity'%(name,h,w,b2))
elif b2>32:
print('hello,%s,your Height is:%s,your Weightis:%s,BMI:%s,obesitiest'%(name,h,w,b2))
你这段代码运行时不会报错吗?
我这边只要用 h = int(input()) 就会报错, 但如果改用 h = float(input()) 就没问题。
奇怪的是,我在命令行里输入 int(1.75),能返回数字1, 照理应该没问题啊。 顶多就会输入的 1.75 会被截成整数 1 导致数据不准确, 怎么会报错呢? 奇了个怪……
a = int(1.75) # OK!
b = int('1.75') # Wrong
如果一定要输入浮点数,可以这样:
c = int(float(input('Please Enter:')))
- 1
三片子