Python选择结构语句分为if语句、if else 语句 、if elif else语句
1.if语句
if语句用于检测表达式是否成立,如果成立则执行if语句内的语句块
if(表达式):
语句块
>>>c = 10
>>>if c > 5
print('c > 5')
运行结果: c > 5
2.if else语句
if(表达式):
语句块1
else:
语句块2
>>>name = 'Damon'
>>>if(name == 'Tom'):
print("hello ,Tom")
else :
print ("hello" , +name)
运行结果:hello,Damon
3.if elif else
if(表达式1):
语句块1
elif(表达式2):
语句块2
else:
语句块3
编程举例:
#-*- coding:utf-8 -*-
score= input("请输入学生成绩:")
score=(int)scoreif(score >= 90:print('A')elif (score >= 80):print('B')elif (score >= 60):print('C')else:print('D')