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

邢台网站建设免费做网站排名/搜索引擎seo关键词优化方法

邢台网站建设免费做网站排名,搜索引擎seo关键词优化方法,阿里云网站建设的步骤过程,怎么免费搭建一个网站python运算符小游戏(全局变量/异常处理);奇数偶数;猜年龄(while/break/continue/);while continue else vs while break else 输出三个数字中的最大值/最小值;倒三角形;99乘法表; 回顶部1python运算符 True 真 正确的 False 假 错误的 num 1 等价于 num num 1 num - 1 …
 

python运算符
小游戏(全局变量/异常处理);奇数偶数;猜年龄(while/break/continue/);while + continue + else vs while + break + else
输出三个数字中的最大值/最小值;倒三角形;99乘法表;




回顶部
1

python运算符

True 真 正确的
False 假 错误的

num += 1 等价于 num = num + 1
num -= 1 等价于 num = num - 1
num *= 2 等价于 num = num * 2
num /= 2 等价于 num = num / 2
num //= 2 等价于 num = num // 2
num %= 2 等价于 num = num % 2
num = 2 等价于 num = num 2

>>> 5/2
2.5
>>> 5//2 # 地板除/整除
2
>>> 9%2 # 取余
1


// 取整除  返回商的整数部分
9//2 输出结果 4 , 9.0//2.0 输出结果 4.0

9//2.0
4.0

Python位运算符:

按位运算符是把数字看作二进制来进行计算的。Python中的按位运算法则如下:

  1. & 按位与运算符:参与运算的两个值,如果两个相应位都为1,则该位的结果为1,否则为0
  2. l 按位或运算符:只要对应的二个二进位有一个为1时,结果位就为1。
  3. ^ 按位异或运算符:当两对应的二进位相异时,结果为1
  4. ~ 按位取反运算符:对数据的每个二进制位取反,即把1变为0,把0变为1。~x 类似于 -x-1
  5. << 左移动运算符:运算数的各二进位全部左移若干位,由"<<"右边的数指定移动的位数,高位丢弃,低位补0。
  6. >> 右移动运算符:把">>“左边的运算数的各二进位全部右移若干位,”>>"右边的数指定移动的位数
  • # 下面是二进制运算
  •   a = 0011 1100
  •      b = 0000 1101
  •  a&b = 0000 1100
  •   a|b = 0011 1101
  •   a^b = 0011 0001
  •    ~a = 1100 0011

 

Python成员运算符

  • in 如果在指定的序列中找到值返回 True,否则返回 False。

x 在 y 序列中 , 如果 x 在 y 序列中返回 True。

  • not in 如果在指定的序列中没有找到值返回 True,否则返回 False。

x 不在 y 序列中 , 如果 x 不在 y 序列中返回 True。

 

Python身份运算符

  • is is是判断两个标识符是不是引用自一个对象

x is y, 类似 id(x) == id(y) , 如果引用的是同一个对象则返回 True,否则返回 Falseis not 

  • is not 是判断两个标识符是不是引用自不同对象

x is not y , 类似 id(a) != id(b)。如果引用的不是同一个对象则返回结果 True,否则返回 False

 id() 函数用于获取对象内存地址

 

Python运算符优先级

 

  • ** 指数 (最高优先级)
    • ~ + - 按位翻转, 一元加号和减号 (最后两个的方法名为 +@ 和 -@)
      • * / % // 乘,除,取模和取整除
        • + - 加法减法
          • >> << 右移,左移运算符
            • & 位 ‘AND’
              • ^ l 位运算符
                • <= < > >= 比较运算符
                  • <> == != 等于运算符
                    • = %= /= //= -= += = *= 赋值运算符
                      • is is not 身份运算符
                        • in not in 成员运算符
                          • not or and 逻辑运算符

 


and 且,并且
只有两个条件全部为True(正确)的时候, 结果才会为True(正确)

条件1 and 条件2
5>3 and 6<2 True

or 或,或者
只要有一个条件为True,则结果为Ture,
5>3 or 6<2
真 或 假

not 不,雅蠛蝶

not 5>3 == False
not 5<3 == True

短路原则
对于and 如果前面的第一个条件为假,那么这个and前后两个条件组成的表达式 的计算结果就一定为假,第二个条件就不会被计算

对于or
如果前面的第一个条件为真,那么这个or前后两个条件组成的表达式 的计算结果就一定为真,第二个条件就不会被计算

True or True and False => True
前面为真 后面(包括and后面)就不计算了

not not True or True and False => True
同理

and or 无先后顺序,即从左往右算(遵循短路原则)

回顶部
2

小游戏(全局变量/异常处理);奇数偶数;猜年龄(while/break/continue/);while + continue + else vs while + break + else

  • 1,return # 可以让一个函数结束
  • 2,break # 可以让一个循环结束
  • 3,exit() # 可以让一个程序结束
global a_  # 定义全局变量
# 一直执行程序
while True:a_ = input('>>')  # 同级缩进,否则报错# 异常处理try:a_ = int(a_)except:print('您输入非数字类型')a_ = 0b_ = 100c_ = 1000if b_ <= a_ <= c_:print("True")else:print("False")

>>12
False
>>123
True
>>fgh
您输入非数字类型
False
>>


# 奇数偶数
num = 1while num <= 100:  # num<=100 等价于 True# while num<=100:   等价于 while True:if num % 2 == 0:print(num)num += 1num = 1while num <= 100:if num % 2 == 1:print(num)num += 1

 


# 猜年龄
age = 50flag = Truewhile flag:user_input_age = int(input("Age is :"))if user_input_age == age:print("Yes")flag = Falseelif user_input_age > age:print("Is bigger")else:print("Is smaller")print("End")

 


# break  # 终止
age = 50while True:user_input_age = int(input("Age is :"))if user_input_age == age:print("Yes")breakelif user_input_age > age:print("Is bigger")else:print("Is smaller")print("End")

 


continue 继续# continue
# 总共10次循环, 当执行continue,结束当次循环
num = 1
while num <= 10:num += 1if num == 3:continueprint(num)

2
4
5
6
7
8
9
10
11


# continue
# 总共10次循环, 当执行continue,结束当次循环
num = 1
while num <= 10:num += 1if num == 3:continueprint(num)
else:print('This is else statement')

2
4
5
6
7
8
9
10
11
This is else statement

 

num = 1
while num <= 10:num += 1if num == 6:breakprint(num)
else:print('This is else statement')

2
3
4
5

 

while + continue + else vs while + break + else

  • else 在程序正常循环的情况下执行,例如continue,
  • else 在程序被中断的情况下不执行,例如break 或者程序前面错误
回顶部
3

输出三个数字中的最大值/最小值;倒三角形;99乘法表;

 

  • 输出三个数字中的最大值/最小值
num1 = int(input("Num1:"))
num2 = int(input("Num2:"))
num3 = int(input("Num3:"))if num1 >= num2 >= num3:print(num1)  # num1最大
elif num1 >= num3 >= num2:print(num1)  # num1最大
elif num2 >= num1 >= num3:print(num2)  # num2最大
elif num2 >= num3 >= num1:print(num2)  # num2最大
elif num3 >= num2 >= num1:print(num3)  # num3最大
else:print(num3)
num1 = int(input("Num1:"))
num2 = int(input("Num2:"))
num3 = int(input("Num3:"))if num1 >= num2:max_num = num1if max_num >= num3:print("Max NUM is", max_num)else:print("Max NUM is", num3)
else:max_num = num2if max_num >= num3:print("Max NUM is", max_num)else:print("Max NUM is", num3)

 

  • 嵌套

while 条件:
....
else:
....

 

statement 语句 


while 条件1:
.....
while 条件2:
....

 

print("hello world.", end="__")  # \n(linux)   \r\n(Windows) \r 光标回到当前行最前面,\n 换行  \r(mac)
print("hello world.", end="__")
print("hello world.", end="__")

hello world.__hello world.__hello world.__

 

num1 = 0
while num1<=5:print(num1,end="_")num2 = 0while num2<=7:print(num2,end="-")num2+=1num1+=1print() #  print(end="\n")

0_0-1-2-3-4-5-6-7-
1_0-1-2-3-4-5-6-7-
2_0-1-2-3-4-5-6-7-
3_0-1-2-3-4-5-6-7-
4_0-1-2-3-4-5-6-7-
5_0-1-2-3-4-5-6-7-

 

height = int(input('高>>'))
width = int(input('宽>>'))
num_h = 1
while num_h <= height:num_w = 1while num_w <= width:print('#', end='')num_w += 1print()num_h += 1

高>>5
宽>>3
###
###
###
###
###

 

width = int(input("width:"))num_width = 1while num_width <= width:print("#", end="")num_width += 1
print()num_width = 1
while num_width <= width:print("#", end="")num_width += 1
print()num_width = 1
while num_width <= width:print("#", end="")num_width += 1
print()num_width = 1
while num_width <= width:print("#", end="")num_width += 1

width:3
###
###
###
###

 

print("#", end="")
print("#", end="")
print("#", end="")
print("#", end="")
print()

####

 

num = 4
while num > 0:print("#", end="")num -= 1
print()

####

 

num2 = 4
while num2 > 0:print('####')num2 -= 1

####
####
####
####

 

height = 2
width = 2num2 = height  # 第一步: 赋值
while num2 > 0:  # 第二步 :num2 == 2
num1 = width  # 第三步: 赋值while num1 > 0:  # 第四步:num1==2   # 第七步:num1 = 1print("#", end="")  # 第五步: 不换行 打印一个#   第八步: 不换行 打印一个#num1 -= 1  # 第六步: num1 = 1   第九步: num1 = 0print()  # 第十步 : 只是换行num2 -= 1  # 第十一步 : num2=1

##
##

 

 

print("1*1=",1)# "1*1=",1  == str(m)+"*"+str(n)+"=",1
m = 2
n = 2print( str(m)+ "*" + str(n) + "=" , m*n  )num = 1
while num <= 10:print(num)num += 1

1
2
3
4
5
6
7
8
9
10

 

  • 倒三角形
line = 5  # 第一步 : 赋值
while line > 0:  # 第二步 line=5tmp = line  # 第三步 : tmp =5   tmp=4while tmp > 0:  # 第四步 : tmp =5   #第七步 tmp=4    #第十步: tmp=3   第十三步 tmp=2print("*", end="")  # 第五步   #第八步        #第十一步               #第十四步tmp = tmp - 1  # 第六步 tmp = 4  # 第九步 tmp=3  # 第十二步 tmp=2   第十五步 tmp= 1print()line -= 1

*****
****
***
**
*

 

  • 正99乘法表
first = 1
while first <= 9:sec = 1while sec <= first:print(str(sec) + "*" + str(first) + "=" + str(sec * first), end="\t")  # \t 制表符sec += 1print()first += 1

1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81

 

  • 倒99乘法表
first = 9
while first > 0:sec = 1while sec <= first:print(str(sec) + "*" + str(first) + "=" + str(sec * first), end="\t")  # \t 制表符sec += 1print()first -= 1

1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*4=4 2*4=8 3*4=12 4*4=16
1*3=3 2*3=6 3*3=9
1*2=2 2*2=4
1*1=1

回顶部
4
回顶部
5
回顶部
6
回顶部
7
回顶部
8

转载于:https://www.cnblogs.com/LL-HLK/p/11080008.html

http://www.lbrq.cn/news/1756225.html

相关文章:

  • wordpress 动态/关键词优化需要从哪些方面开展?
  • 海外购物app/seo外包公司报价
  • 家居网站建设全网营销/如何优化搜索引擎的搜索功能
  • 高端的网站开发公司/买卖链接网
  • 邢台网站建设/营销案例分析
  • php做网站弊端/百度精简版网页入口
  • 一个云主机怎么挂两个网站/软文推广例子
  • 集宁做网站的公司/优化营商环境建议
  • 在线A视频网站(级做爰片)/电脑培训学校排名
  • ip怎么做网站/西安百度网站快速排名
  • 网站建设技术有哪些/全国疫情高峰感染高峰
  • 宁波五金网站建设/国内疫情最新消息
  • 为什么网站浏览不是做的那样/电商培训机构有哪些?哪家比较好
  • 私彩网站是怎么建设的/上海快速排名优化
  • 怎么促成客户做网站/软件制作
  • 哪些网站做的比较好/北京网站建设
  • 网站建设做网站需要多少钱/广州企业推广
  • 杭州 网站建设 哪家强/seo和sem是什么意思啊
  • 网站横幅怎做/软文推广网站
  • 龙岗建设网站/济南网络优化厂家
  • 音视频娱乐网站开发商/好用的搜索引擎有哪些
  • 广州网站推广电话/谷歌浏览器下载官网
  • yw12777域名查询/seo教程seo优化
  • 关于公示网站建设的计划书/泰安做网站公司哪家比较好
  • 网站建设服务 杭州/建网站建设
  • 乌鲁木齐做企业网站/免费网站开发平台
  • 个人网页设计与实现ppt/互联网广告优化
  • 制作网站需要什么软件/seo外链建设的方法
  • 中卫市住房建设局网站/3seo
  • 天津平台网站建设报价/手机网站智能建站
  • 从缓存 CAS 看Kimi K2使用的MuonClip优化器
  • 2025年中国品牌全球化发展分析:中国品牌在社交渠道、电商平台及官网流量方面显著增长
  • Elasticsearch+Logstash+Kibana部署
  • RTL编程中常用的几种语言对比
  • HashMap详解
  • ethers.js-8-bigNmber和callstatic模拟