文章目录
1. if语句/分支语句/条件语句
if语句有三种结构:if, if-else, if-elif-else
1.1 if 结构
if 条件: (以英文冒号结尾)
语句组1(在Python规范里推荐使用4个半角空格)
满足条件True,运行语句组1,结束;不满足条件False,结束
# coding = utf-8
score = int(input("请输入一个0~100的整数:"))
if score >= 85 :
print("Very good!") #在Python规范里推荐使用4个半角空格
if score < 60 : # 注意不要忘记":"
print("You need to work hard.")
if (score >=60) and (score <85) :
print("Keep going on!")
1.2 if-else 结构
if 条件:
语句组1
else: (以英文冒号结尾)
语句组2(在Python规范里推荐使用4个半角空格)
满足条件True——语句组1——结束
不满足条件False——语句组2——结束
score = int(input("请输入一个0~100的整数:"))
if score >=60 :
if score >= 85:
print("Very good")
else :
print("Keep going on!"