作业1:用条件语句写一个BMI(体重除以身高的平方)指数
- 用条件语句写一个BMI(体重除以身高的平方)指数
- 低于18.5:过轻
- 18.5 - 25 正常
- 25 - 28 过重
- 28 - 32 肥胖
- 高于32 严重肥胖
weight = input("请输入体重:")
height = input("请输入身高:")
BMI = float(float(weight)/(float(height)**2))
#计算bmi的公式
if BMI<= 18.5:
print("弱不禁风",BMI)
elif BMI<=25:
print("继续保持",BMI)
elif BMI<=28:
print("男生最喜欢的女孩的身材",BMI)
elif BMI<=32:
else:
print("珍爱生命,控制食欲,多运动,多撩妹")
作业2:计算从1到100所有奇数的和
方法1
def odd1():
sum = 0
for i in range(0,101,2):
# print(i)
sum = sum + i
print("从1到100所有奇数的和为:",sum)
if __name__ == '__main__':
odd1()
方法2
def odd2():
sum = 0
for i in range(0,101):
if i % 2 !=0:
sum = sum+i
print("从1到100所有奇数的和为:", sum)
if __name__ == '__main__':
odd2()
作业3:计算从1到100所有偶数的和
方法1
def even1():
sum = 0
for i in range(1, 101, 2):
# print(i)
sum = sum + i
print("从1到100所有偶数的和为:",sum)
if __name__ == '__main__':
even1()
方法2
def even2():
sum = 0
for i in range(1,101):
if i % 2 == 0:
print(i)
sum = sum + i
print("从1到100所有偶数的和为:",sum)
if __name__ == '__main__':
even2()
作业4:用while计算1到100的乘积
def Product():
product = 1
num = 1
while num <= 100:
product = num * product
num = num + 1
print("1到100的乘积",product)
if __name__ == '__main__':
Product()