2.17 流程控制
> 条件语句




> 循环语句
while循环语句:
for循环语句:
> 示例代码
Last updated
Was this helpful?




Last updated
Was this helpful?
Was this helpful?
print("请输入体重(kg):")
weight = float(input())
if weight > 90:
print("胖子,该减肥啦!!!")print("请输入体重(kg):")
weight = float(input())
if weight > 90:
print("胖子,该减肥啦!!!")
else:
print("小样,身材保持的不错嘛!")# 计算BMI指数
print("请输入体重(kg):")
weight = float(input())
print("请输入身高(m):")
height = float(input())
BMI = weight / height**2
if BMI < 20:
print("你的BMI指数是%.2f,太轻了哟!" %BMI)
elif BMI > 25:
print("你的BMI指数是%.2f,太重了哟!" %BMI)
else:
print("你的BMI指数是%.2f,非常正常,请保持!" %BMI)# 统计6出现在2的100次方中的次数:
num = 2**100
print(num)
count = 0
while num > 0:
if num % 10 == 6:
count = count + 1
num = num // 10
print(count)# 统计6出现在2的100次方中的次数:
num = 2**100
print(num)
count = 0
for digit in str(num):
if digit == "6":
count = count + 1
print(count)for i in range(10):
print(i)for x in range(1,10):
print(x) #结果不包含最后的10