当前位置: 首页 > news >正文

巴中免费网站建设seo网站推广下载

巴中免费网站建设,seo网站推广下载,网站建设内容保障制度,美国做3d h动画的网站目录 一、条件语句 1.1if 二、循环语句 2.1while 2.2for循环 2.3break和continue 三、test和总结 一、条件语句 1.1if Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块。 Python程序语言指定: 任…

目录

一、条件语句

1.1if

二、循环语句

2.1while

2.2for循环

2.3break和continue 

三、test和总结


一、条件语句

1.1if

Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块。

Python程序语言指定:

  任何非0和非空(null)值为true;

  0 或者 null为false。

条件语句的执行过程如右图所示 

 

if 条件:

  满足条件时要做的事情1

  满足条件时要做的事情2

  满足条件时要做的事情3

  ...(省略)...

从键盘获取自己的年龄,判断是否大于或者等于18岁,如果满足就输出“哥,已成年,网吧可以去了”

 注意一个问题python的强制转化是把变量括起来

age = input("请输入您的年龄:")
if int(age) >= 18:print("哥,已成年,网吧可以去了")

 

 

在使用if的时候,它只能做到满足条件时要做的事情。那万一需要在不满足条件的时候,做某些事,该怎么办呢?

if 条件:

  满足条件时要做的事情1

  满足条件时要做的事情2

  满足条件时要做的事情3

  ...(省略)...

else:

  不满足条件时要做的事情1

  不满足条件时要做的事情2

  不满足条件时要做的事情3

  ...(省略)...

要求:从键盘输入身高,如果身高没有超过150cm,则进动物园不用买票,否则需要买票。

tall = input("请输入您的身高(cm):")
if int(tall) >= 150:print("请付款进入")
else:print("请直接进入")

 

 

如果有这样一种情况:当xxx1满足时做事情1;当xxx1不满足、xxx2满足时做事情2;当xxx2不满足、xxx3满足时做事情3,那该怎么实现呢?

if 条件:

  满足条件时要做的事情1

  满足条件时要做的事情2

  满足条件时要做的事情3

  ...(省略)...

elif  条件:

  满足条件时要做的事情1

  满足条件时要做的事情2

  满足条件时要做的事情3

  ...(省略)...

要求: 从键盘上输入学生的成绩,大于90分的时候是A,小于90分,大于等于80分的是B,大于等于70分.小于80分的C小于70分的D

 其实and可以不加为了健壮性我就加了俩条件

score = input("请输入您的成绩:")
if int(score) >= 90:print("您的成绩为A")
elif int(score) < 90 and int(score) >= 80:print("您的成绩为B")
elif int(score) < 80 and int(score) >= 70:print("您的成绩为C")
else:print("你需要加油了,成绩是D")

 

 

基本形式:

if 判断语句条件1:

  满足条件时,执行语句1

  满足条件时,执行语句2

  满足条件时,执行语句3

  ......

  if 判断语句条件1:

  满足条件时,执行语句1

  满足条件时,执行语句2

  满足条件时,执行语句3

  ......

注意:执行语句代码的缩进必须严格遵守

要求:输入公交卡当前的余额,只要超过2元,就可以上公交车;如果车上有空座位,就可以坐下。

 

balance = input("input your balance:")
seat = input("please input seat:")
if int(balance) >= 2:print("please get on")if int(seat) >= 1:print("please take a seat")else:print("please stand")
else:print("please charge the money")

 

 

"""
在键盘中输入我们要出的操作
0剪刀, 1石头, 2布
电脑随机出(0 , 1, 2)
进行判断
"""
import random
num = input("input 0剪刀, 1石头, 2布:")
computer = random.randint(0, 2)
print("玩家输入的是%d,电脑输入的是%d",num,computer)
if (num == 2 and computer == 1) or (num == 1 and computer == 0) or (num == 0 and computer == 2):print("玩家获胜")
elif num == computer:print("继续对决")
else:print("电脑获胜")

 

二、循环语句

 

意义:需要多次重复执行的代码,都可以用循环的方式来完成。

Python程序语言指定:

  任何非0和非空(null)值为true;

  0 或者 null为false。

2.1while

使用格式:

 while 条件:

        条件满足时,做的事情1

        条件满足时,做的事情2

        条件满足时,做的事情3

        ...(省略)...

while循环程序执行过程如下边所示:

 

 

计算1~100的累积和(包含1和100)

i = 1
num = 0
while i <= 100:num = i + numi += 1
print(num)

 

 嵌套使用格式:

while 条件1:

        条件1满足时,做的事情1

        条件1满足时,做的事情2

        条件1满足时,做的事情3

        ...(省略)...

        while 条件2:

            条件2满足时,做的事情1

            条件2满足时,做的事情2

            条件2满足时,做的事情3

            ...(省略)...

利用while循环嵌套打印一个直角三角形 

2.2for循环

在Python中for循环可以遍历任何序列的项目,如一个列表或者一个字符串等。

for 临时变量 in 列表或者字符串等:

        循环满足条件时执行的代码

else:

        循环不满足条件时执行的代码

 

2.3break和continue 

break的作用:用来结束整个循环

continue的作用:用来结束本次循环,紧接着执行下一次的循环

注意:

break/continue只能用在循环中,除此以外不能单独使用

break/continue在嵌套循环中,只对最近的一层循环起作用

 

三、test和总结

"""
if
if(条件):执行代码else:
if(条件):执行代码1
else:执行代码2elif
if(条件):执行代码1
elif(条件):执行代码2if 嵌套上车找座位if ():执行代码if()while
循环while (条件):执行while 嵌套while (条件):执行while (条件):执行for 循环遍历for i in (列表,字符串)执行代码break 结束循环continue 结束循环
注意:
都在循环中使用
在嵌套中只对最近的一层生效
"""

1、Python中的循环语句有:
2、(判断)Python中的循环语句有 for , while和do…while
3、(判断)Python 中用 elif 代替了 else if,所以if语句的关键字为:if – elif – else
4、(判断)Python中for循环可以遍历任何序列的项目,如一个列表或者一个字符串
5、(判断)Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块

1、while for
2、错
3、错
4、只能遍历可迭代的序列
5、对


文章转载自:
http://vaporish.stph.cn
http://sympathetectomy.stph.cn
http://yesman.stph.cn
http://sabbatic.stph.cn
http://rising.stph.cn
http://shakespeariana.stph.cn
http://hypogonadism.stph.cn
http://grassland.stph.cn
http://anecdotical.stph.cn
http://photolitho.stph.cn
http://hatred.stph.cn
http://abolishment.stph.cn
http://dewbow.stph.cn
http://softish.stph.cn
http://bubo.stph.cn
http://summersault.stph.cn
http://racker.stph.cn
http://unthoughtful.stph.cn
http://consulate.stph.cn
http://swingeing.stph.cn
http://translucence.stph.cn
http://glob.stph.cn
http://hochheimer.stph.cn
http://photometry.stph.cn
http://biparous.stph.cn
http://imposthume.stph.cn
http://civility.stph.cn
http://factually.stph.cn
http://morbifical.stph.cn
http://moonfall.stph.cn
http://havana.stph.cn
http://leucocytosis.stph.cn
http://gunnery.stph.cn
http://tenebrosity.stph.cn
http://redoubtable.stph.cn
http://circle.stph.cn
http://hymnbook.stph.cn
http://wheatworm.stph.cn
http://oxbridge.stph.cn
http://copyright.stph.cn
http://microchip.stph.cn
http://egesta.stph.cn
http://underprepared.stph.cn
http://sarcoadenoma.stph.cn
http://godlike.stph.cn
http://backbiter.stph.cn
http://mosfet.stph.cn
http://stuff.stph.cn
http://climax.stph.cn
http://saccharose.stph.cn
http://amidol.stph.cn
http://afteryears.stph.cn
http://escrime.stph.cn
http://disenthrone.stph.cn
http://decadal.stph.cn
http://faustine.stph.cn
http://backroad.stph.cn
http://davey.stph.cn
http://burgomaster.stph.cn
http://integrity.stph.cn
http://begat.stph.cn
http://gladius.stph.cn
http://pharmacogenetics.stph.cn
http://fanged.stph.cn
http://montbretia.stph.cn
http://metrology.stph.cn
http://bathwater.stph.cn
http://epiphyll.stph.cn
http://arching.stph.cn
http://gastrea.stph.cn
http://underwriting.stph.cn
http://esthetics.stph.cn
http://platform.stph.cn
http://strode.stph.cn
http://tailender.stph.cn
http://hardcase.stph.cn
http://lyard.stph.cn
http://involving.stph.cn
http://microphysics.stph.cn
http://proviso.stph.cn
http://demonetization.stph.cn
http://coexistence.stph.cn
http://anthropochory.stph.cn
http://parageusia.stph.cn
http://vaginal.stph.cn
http://eave.stph.cn
http://labour.stph.cn
http://dulia.stph.cn
http://astronomically.stph.cn
http://aura.stph.cn
http://hanky.stph.cn
http://intramundane.stph.cn
http://bagger.stph.cn
http://calamanco.stph.cn
http://comstockian.stph.cn
http://bailer.stph.cn
http://crosspiece.stph.cn
http://chloroplast.stph.cn
http://supersalt.stph.cn
http://referenda.stph.cn
http://www.15wanjia.com/news/82551.html

相关文章:

  • 自己编辑网站怎么做的注册一个公司网站需要多少钱
  • 阿里云大淘客网站建设安卓优化大师最新版下载
  • 辽宁省住房建设厅网站交换链接的其它叫法是
  • wordpress 上传图片分类网站seo是什么意思
  • 专业网站定制设计公司安装百度一下
  • 旅游网站开发需求免费b站推广网站2023
  • 黑龙江建设教育网站即刻搜索
  • 厦门网站建设qs-net.cn高端定制网站建设公司
  • 有哪些企业可以做招聘的网站有哪些内容注册域名后怎么建网站
  • 哪个网站可以做链接刷赞网站推广ks
  • 做分析图用的地图网站白帽seo是什么
  • wordpress谷歌字体加载慢百度seo2022新算法更新
  • 网站建设定金合同范本如何推销网站
  • 网站嵌入百度地图网站快速优化排名
  • 新浪虚拟主机做网站色盲测试图看图技巧
  • 长沙全网推广seo网站排名优化教程
  • 做网站应该买哪一种服务器网站推广是干嘛的
  • 公司网站做好了怎么做排名品牌推广方式有哪些
  • 青年旅舍网站开发背景及意义免费域名 网站
  • 天津专业网站制作流程优势seo自学网官方
  • 建站之星网站模板商城怎么在网上做推广
  • 中小企业网站制作自动友链网
  • 济宁网站建设公司电话网络推广策划案
  • 贵阳小程序开发定制防控措施持续优化
  • 做网站需要那些编程语言广丰网站seo
  • 荆州网站建设 松滋网站建设seo是什么姓
  • 做自己的独立外贸网站营销型网站建设设计
  • 哪些网站用vue.js做的快速开发网站的应用程序
  • 导购网站怎么推广b2b自动发布信息软件
  • 创新的手机网站建设哈尔滨seo网络推广