1.基本概念
Python选择程序设计是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块。
Python程序语言指定任何非0和非空(null)值为true,0 或者 null为false。
2.程序基本结构
if 判断条件:
执行语句……
else:
执行语句……
3.实例
3.1 判断一个人年龄属于未成年人还是成年人
print("请输入你的年龄:")
age = input()
age = int(age)
if (age >= 18):
print("你成年了")
else:
print("你还没有成年")
3.2判断是否是闰年
print("请输入一个年份:")
year = input()
year = int(year)
if((year%4==0 and year%100!=0)or(year%400==0)):
print(year,"是闰年")
else :
print(year,"不是闰年")