一、简单的if语句

举例

 if money > 10000:
  print '我们去旅游吧' #左侧一定要有缩进,一般4个空格
 print '请输入学生的考试成绩'
score = print ()
print score >=60
if score >=60:
  print '合格' #结果
#请输入学生考试成绩
#
#True
#合格 #请输入学生的考试成绩
#
#False

二、条件表达式

三、if-else-elif多重if语句

if-else语句示例

 print '请输入学生的考试成绩'
score = input ()
print score >= 60
if score >= 60:
  print '合格'
else:
  print '还需继续努力' #结果
#请输入学生的考试成绩
#
#False
#还需继续努力

多重if语句示例

正确示例

 print '请输入学生考试成绩'
score = input()
if score >= 90:
  print '优秀'
elif score >= 70:
  print '良好'
elif score >= 60:
  print '合格'
else:
  print '还需努力' #结果
#请输入学生考试成绩
#
#True
#良好

反面示例

 print '请输入学生考试成绩'
score = input()
if score >= 60:
  print '优秀'
elif score >= 70:
  print '良好'
elif score >= 90:
  print '合格'
else:
  print '还需努力' #结果
#请输入学生考试成绩
#
#True
#合格
#语句是从上到下依次执行的,当大于等于60条件成立后,就不往下判断了,所以输出为合格

python基础之条件判断的更多相关文章

  1. Python基础:条件判断与循环的两个要点

    一.条件判断: Python中,条件判断用if语句实现,多个条件判断时用if...elif实现:看下面一段程序 #python 3.3.5 #test if...elif age = 20 if ag ...

  2. python基础3 条件判断 if嵌套

    if单向判断: stonenumber=6#为宝石数量赋值 if stonenumber>=6: #条件:如果你拥有的宝石数量大于等于6个 print('你拥有了毁灭宇宙的力量') #结果:显示 ...

  3. Python基础(条件判断,循环,占位符等)

    Python 自动化 系统开发用的语言和自动化脚本可以不同 学习peython可用于: 网路爬虫,数据分,web开发,人工智能,自动化运维,自动化测试,嵌入式,黑客 第三方库比较全 脚本语言:功能单一 ...

  4. python基础之条件判断和循环

    1.条件判断 age = 3 if age >= 18: print('adult') elif age >= 6: print('teenager') else: print('kid' ...

  5. Python基础教程-条件判断和循环

    Python条件判断 在Python中用if语句实现: age = 20 if age >= 18: print 'your age is :',age print 'adult' 根据Pyth ...

  6. python基础知识--条件判断和循环

    一.输入输出 python怎么来接收用户输入呢,使用input函数,python2中使用raw_input,接收的是一个字符串,输出呢,第一个程序已经写的使用print,代码入下: 1 name=in ...

  7. python学习第六天:python基础(条件判断、循环)

    条件判断 格式 if <条件判断1>: <执行1> elif <条件判断2>: <执行2> elif <条件判断3>: <执行3> ...

  8. Python基础:条件判断 &&循环

    1:条件判断 2:循环 2.1:for 2.2  while 小结: continue :跳出本次循环 进行下次循环,  break :结束循环体.

  9. Python 基础之三条件判断与循环

    If……else 基本结构: If condition: do something else: do something 或者 If condition: do something elif cond ...

随机推荐

  1. JPA 注解详解

    @Entity --声明为一个实体类bean @Table (name= "promotion_info" ) --为实体bean映射指定表(表名="promotion_ ...

  2. c语言语法目录一

    1.#include<stdio.h> include 是要告诉编译器,包含一个头文件 在c语言中,任何库函数调用都需要提前包含头文件 <头文件> 代表让c语言编译器去系统目录 ...

  3. laravel中的数据库操作(增删改查)方法一

    导入命名空间和DBnamespace App\Http\Controllers; use Illuminate\Support\Facades\DB; public function index(){ ...

  4. Logistic Regression 用于预测马是否生病

    1.利用Logistic regression 进行分类的主要思想 根据现有数据对分类边界线建立回归公式,即寻找最佳拟合参数集,然后进行分类. 2.利用梯度下降找出最佳拟合参数 3.代码实现 # -* ...

  5. 如果你的资源贫乏,那么专注做好一件事将是你的唯一出路(no reading yet)

    http://www.jianshu.com/p/8784f0fd7ab8/comments/1161511

  6. T-SQL分页功能存储过程

    分页功能存储过程 ALTER PROCEDURE [dbo].[P_SplitPagesQuery] @TablesName NVARCHAR(MAX),--表名或视图名(只能传单一表名) @PK N ...

  7. atom markdown报错:AssertionError: html-pdf: Failed to load PhantomJS module.

    今天安装markdown-pdf之后运行的时候报错: AssertionError: html-pdf: Failed to load PhantomJS module. You have to se ...

  8. [GO]append的扩容

    package main import "fmt" func main() { s := make([], ) oldcap := cap(s) ; i < ; i++{ s ...

  9. OSG3.2+Qt5.2.1+VS2012+OSGEarth 2.5编译问题记录

    问题1:CMake Error at D:/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake: ...

  10. Load-time relocation of shared libraries

    E原文地址:http://eli.thegreenplace.net/2011/08/25/load-time-relocation-of-shared-libraries/ This article ...