码迷,mamicode.com
首页 > 编程语言 > 详细

python_4

时间:2017-10-15 22:40:46      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:整数   ber   over   word   pytho   php   引用   变量   不能   

关于if else

python中

if 变量的条件 :

  执行条件语句;

else:

  执行条件语句;

 

 

if 变量的条件1:

  执行条件语句;

elif变量的条件2:

  执行条件语句;

elif 变量的条件3:

  执行条件语句;

else:

  执行条件语句4;

 

if语句执行有个特点,它是从上往下判断,如果在某个判断上是True,把该判断对应的语句执行后,就忽略掉剩下的elifelse,所以,请测试并解释为什么下面的程序打印的是teenager

 

if x:
    print(‘True‘)



input()返回的数据类型是strstr不能直接和整数比较,必须先把str转换成整数。Python提供了int()函数来完成这件事


s = input(‘birth: ‘)
birth = int(s)
if birth < 2000:
    print(‘00前‘)
else:
    print(‘00后‘)


作业


height = 1.75
weight = 80.5
BMI = weight/(height*height);
if BMI>32:
print("serious heavier %.1f" %BMI);
elif BMI>28 and BMI<32:
print("obisity %.1f" %BMI);
elif BMI>25 and BMI<28:
print("overweight %.1f" %BMI);
elif BMI>18.5 and BMI<25:
print("normal %.1f" %BMI);
elif BMI<18.5:
print("too light %.1f" %BMI);
else:
print("what the hell???")


上面材料引用廖雪峰!

本博客所刊登的所有内容,

未经创作者合法授权,禁止一切形式转载,违者必究

python_4

标签:整数   ber   over   word   pytho   php   引用   变量   不能   

原文地址:http://www.cnblogs.com/jialikesensi/p/7674249.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!