流程控制之 if 判断
语法一:
if 条件:
代码1
代码2
代码3 gender='female'
age=18
is_beautiful=True if gender == 'female' and age > 16 and age < 20 and is_beautiful:
print('开始表白。。。。') print('其他代码') 语法二:
if 条件:
代码1
代码2
代码3
else:
代码1
代码2
代码3 gender='female'
age=26
is_beautiful=True if gender == 'female' and age > 16 and age < 20 and is_beautiful:
print('开始表白。。。。')
else:
print('阿姨好') print('其他代码') 语法三:
if 条件1:
if 条件2:
代码1
代码2
代码3 gender='female'
age=18
is_beautiful=True
is_successfull=True if gender == 'female' and age > 16 and age < 20 and is_beautiful:
print('开始表白。。。。')
if is_successfull:
print('在一起,,,')
else:
print('逗你玩呢。。。')
else:
print('阿姨好') print('其他代码') 语法四:
if 条件1:
代码1
代码2
代码3
elif 条件2:
代码1
代码2
代码3
elif 条件3:
代码1
代码2
代码3
.......
else:
代码1
代码2
代码3 '''
如果:成绩>=90,那么:优秀 如果成绩>=80且<90,那么:良好 如果成绩>=70且<80,那么:普通 其他情况:很差
''' score=input('your score: ')
score=int(score) if score >= 90:
print('优秀')
elif score >= 80:
print('良好')
elif score >= 70:
print('普通')
else:
print('很差')
流程控制之 if 判断的更多相关文章
- 基础运算符补充,流程控制之if判断/while循环
常量 常量即指不变的量.在python中没有一个专门 的语法代表常量,程序员约定俗成地用变量名全部被大写代表常量. AGE_OF_OLDBOY = 56 基础运算符补充 1.算术运算 加减乘除+ - ...
- 格式化输出的三种方式,运算符及流程控制之if判断
''' 格式化输出的三种方式,运算符及流程控制之if判断 ''' # 格式化输出的三种方式 # 一.占位符 程序中经常会有这样场景:要求用户输入信息,然后打印成固定的格式 比如要求用户输入用户名和年龄 ...
- [基本运算符、流程控制之if判断、与用户交互、深浅拷贝]
[基本运算符.流程控制之if判断.与用户交互] 基本运算符 1.算数运算符 python支持的算术运算符与数学上计算的符号使用是一致的 salary = 3.3 res = salary * 12 p ...
- 流程控制之if判断
目录 语法(掌握) if if...else if...elif...else 练习(掌握) 练习1:成绩评判 练习2:模拟登录注册 if的嵌套(掌握) 语法(掌握) if判断是干什么的呢?if判断其 ...
- 流程控制之if判断,while循环,for循环
if判断? 什么是if判断? 判断一个条件如果成立则做...不成立则... 为什么要有判断? 让计算机像人一样具备判断的能力 如何用if判断 if 条件1: code1 code2 cod ...
- day4 四、流程控制之if判断、while循环、for循环
一.if判断 1.语法一: if 条件: 条件成立时执行的子代码块 代码1 代码2 代码3 示例: sex='female' age= is_beautiful=True and age < a ...
- 廖雪峰Java1-3流程控制-3条件判断
1.if条件判断的格式 if (条件) { 代码块 } if (条件) { 代码块1 } else { 代码块2 } if (条件1) { 代码块1 } else if { 代码块2 } else { ...
- Python流程控制-2 条件判断
条件判断 条件判断是通过一条或多条判断语句的执行结果(True或者False)来决定执行的代码块. 在Python语法中,使用if.elif和else三个关键字来进行条件判断. if语句的一般形式如下 ...
- ansible-playbook流程控制-when条件判断
1. ansible-playbook添加判断 when相当于shell脚本里的if 判断,when语句就是用来实现这个功能的,它是一个jinja2的语法,但是不需要双大括号,用法很简单 1 ...
- python基础之流程控制(if判断和while、for循环)
程序执行有三种方式:顺序执行.选择执行.循环执行 一.if条件判断 1.语句 (1)简单的 if 语句 (2)if-else 语句 (3)if-elif-else 结构 (4)使用多个 elif 代码 ...
随机推荐
- Linux下CenOS系统 安装Redis
1.redis下载 进入root目录:cd /root(目录可自定义) wget http://download.redis.io/releases/redis-3.2.10.tar.gz 红色部 ...
- nova file injection的原理和调试过程
file injection代码 file injection原理来讲是比较简单的,在nova boot命令中,有参数--file,是将文件inject到image中 nova boot --flav ...
- The algorithm learning of sort which include Bubblesort,Insertsort,Quicksort and Mergesort.
Notice : these algorithms achieved by Java. So,let's going to it. firstly, what is Bubblesort? why w ...
- [Swift]LeetCode82. 删除排序链表中的重复元素 II | Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [Swift]LeetCode343. 整数拆分 | Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- [Swift]LeetCode609. 在系统中查找重复文件 | Find Duplicate File in System
Given a list of directory info including directory path, and all the files with contents in this dir ...
- [Swift]LeetCode961. 重复 N 次的元素 | N-Repeated Element in Size 2N Array
In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeate ...
- 面试题:反转字符串(leetcode344)
编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 char[] 的形式给出. 不要给另外的数组分配额外的空间,你必须原地修改输入数组.使用 O(1) 的额外空间解决这一问题. 你可以 ...
- vue-cli中webpack配置详解
vue-cli是构建vue单页应用的脚手架,命令行输入vue init <template-name> <project-name>从而自动生成的项目模板,比较常用的模板有we ...
- C# 使用 HttpClient 调用 WebService 提示 NoSOAPAction
问题 在自行构造 HttpClient 请求 SOAP 接口之后,返回 500 错误,并且提示 NoSOAPAction 信息. 原因 造成这个问题的主要原因是因为缺少了 SOAPAction 标头, ...