



在编程时,当需要根据条件表达式的值确定下一步的执行流程时,通常会用到选择结构。最为常用的选择结构语句为if语句。例如:
>>>x = 1
>>>if(x > 0):
print(x)
运行结果:
1
有时候,我们希望输出自己设定的一句话或者某个提示,例如,当学生成绩低于60分时为不及格,大于等于60分、小于80分时为良好,大于等于80分时为优秀。此时可以通过如下代码实现:
#!/usr/bin/python
#coding:utf-8
studentScore = int(input('Scores of students: '))
if (studentScore < 60):
print('不及格')
if ( 60<=studentScore<80):
print('良好')
if (studentScore>=80):
print('优秀')
在终端运行Python脚本,并在提示“Scores of student:”后输入相应的学生分数,即可返回相应不及格、良好或者优秀的结果。