博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2018/09/04循环+运算
阅读量:7022 次
发布时间:2019-06-28

本文共 1947 字,大约阅读时间需要 6 分钟。

一:while循环

定义: 只要条件成立,就一直循环执行循环代码

机构:

while 条件:

  循环执行代码

else:

  执行代码2

例如:

while True:

  print('0-0')

该函数则无限循环打印'0-0',直至天荒地老!

指令:break(推出本层循环)

       continue(推出本次循环)

 

 

二格式化输出

占位符:%  ( %d,占位指定取数值,%s: 占位指定取字符串,%r :  占位还原取值函数)

三 运算

python里面包含数学运算(如= - * / ),逻辑运算(and,or,not) 比较运算( ==   ,  <=  ,<= 等)

        and 并且。 左右两端同时为真。 结果才能是真

        or  或者。 左右两端有一个是真。 结果就是真
        not 非真即假, 非假即真

x or y  -> ( 如果x为0,取y,否则取x)

x and y   (如果x为0,则取X,否则取y)

运算顺序:  () > not > and > or

编码:

最早的计算机编码:ASCII 占8位

中国:

GBK : 占16位

最早的万国码:  unicode  占 32位

UTF-8: 可变长万国码,占位最短8位

UTF-16: 可变长万国码,占位最短16位

UTF-32: 可变长万国码,占位最短32位

 

 

print(1>1 or 3<4 or 4>5 and 2>1 and 9>8 or 7<6) #True print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ) #false print(8 or 3 and 4 or 2 and 0 or 9 and 7 ) #8 print(0 or 2 and 3 and 4 or 6 and 0 or 3 ) #4 print(6 or 2 > 1) #6 print(3 or 2 > 1) #3 print(0 or 5 < 4 ) # False print(5<4 or 3) #3 print(2>1 or 6) # true print(3 and 2>1) # 3 print(0 and 3>1) # 0 print(2>1 and 3) # 3 print(3>1 and 0) # 0 print(3>1 and 2 or 2<3 and 3 and 4 or 3>2) #2 while 条件:    执行代码1 else:    执行代码2 guess_num = int(input('请猜测幸运数字:')) while guess_num != 66: if guess_num > 66: print('猜大了!')     guess_num = int(input('请猜测幸运数字:'))   elif guess_num < 66:   print('猜小了!')     guess_num = int(input('请猜测幸运数字:')) else: print('You are right !') guess_num = int(input('请输入正确的数字:')) count = 1 while guess_num != 66:   if count ==3:   print('Your are stupid !')   break elif guess_num > 66:  print('猜大了!')   elif guess_num <66:   print('猜小了!') elif guess_num == 66:   break     print('Your are right!')     count += 1   guess_num = int(input('请输入正确的数字:')) else: print('You are right !') num = 1 while num <= 10:   if num != 7:   print(num)  num = num + 1 count = 1 while count <10: count += 1  if count == 7: continue print(count) sum = 0 count = 1 while count <= 100: sum += count count +=1 print(sum) count = 1 while count <=50: print(count * 2 -1) count +=1

转载于:https://www.cnblogs.com/tcpblog/p/9588369.html

你可能感兴趣的文章
Ajax理解
查看>>
第一次模拟建站2
查看>>
linux 系统审计audit详解
查看>>
linux命令行下的ftp多文件下载和目录下载
查看>>
JAVA对象克隆
查看>>
MySQL审计插件使用
查看>>
我的友情链接
查看>>
关于securecrt7.2版本安装在win8系统激活的问题
查看>>
我的友情链接
查看>>
C028 unable to connect to siebel gateway name server
查看>>
PLSQL Developer连接远程Oracle数据库
查看>>
JS一个非常经典的问题:在遍历数组时对DOM监听事件,索引值将始终等于遍历结束后的值...
查看>>
python 路径问题
查看>>
flink could not find implicit value for evidence parameter of type
查看>>
Centos6.3 下apache-solr-3.6.2安装和配置
查看>>
Windows程序中的字符编码问题
查看>>
iOS应用崩溃日志分析
查看>>
Redhat安装hba卡,配置emc powerpath,配置LVM
查看>>
html 的最简洁的遮罩
查看>>
我的友情链接
查看>>