小白的python进阶历程------11.python的条件语句

Python的条件语句是通过一条或多条语句的执行结果(True或者False)来决定直接下来所要执行的代码块。


 1).if ...语句:

num = int(input("请输入一个整数:"))
if num % 2 == 0:
    print('是偶数!')
if num % 2 == 1:
    print('是奇数!')
print('程序结束...')

2).if...else...语句

height = 180
if height >= 175:
    print("You are quite tall!")
else:
    print("You are short!")

3).if...elif...elif...(...)...else...语句

age = 20
if age < 18 :
    print("未成年")
elif age < 60:
    print("成年人")
elif age < 130:
    print("老年人")
else:
    print("非人类")

 

posted @ 2018-09-27 19:43  chen_sang  阅读(174)  评论(0编辑  收藏  举报