Python笔记二

逻辑运算符

or 或者

and 并且

not 取反

you = input(“你去吗?”)
your = input(“你们一起去吗?”)
if you == “yes” or your == “yes”:
print(“OK”)
else:
print(“ON”)
if you == “yes” and your == “yes”:
print(“OKOKOK”)
else:
print(“NONONO”)
if not (you == “yes”):
print(“NONO”)
else:
print(“yes”)

while 语句

num = 1
while num <= 100:
print(num)
num += 1

if 嵌套

if num == 1:
print(“1”)
if num == 2:
print(“2”)
else:
print(“333”)
else:
print(“222”)

num = 1
while num <= 5:
print("*" * num)
num += 1
*
**




i = 1
while i <= 5:
j = 1
while j <= i:
print("*", end="")
j += 1
print("")
i = i + 1
*
**




num = 1
while num <= 5:
print("*****" )
num += 1






i = 1
while i <= 5:
j = 1
while j <= 5:
print("*", end="")
j = j + 1
print("")
i = i + 1





i = 1
while i <= 9:
j = 1
while j <= i:
print("%d*%d=%d \t"%(j,i,ij), end="")
j += 1
print("")
i = i + 1
1
1=1
12=2 22=4
13=3 23=6 33=9
1
4=4 24=8 34=12 44=16
1
5=5 25=10 35=15 45=20 55=25
16=6 26=12 36=18 46=24 56=30 66=36
17=7 27=14 37=21 47=28 57=35 67=42 77=49
1
8=8 28=16 38=24 48=32 58=40 68=48 78=56 88=64
1
9=9 29=18 39=27 49=36 59=45 69=54 79=63 89=72 99=81
name = “zhangsan”
for teme in name:
print(teme)

i = 1
while i <= 100:
if i % 2 == 0:
print(i)
i += 1

i = 1
num = 0
while i <= 100:
if i % 2 == 0:
print(i)
num += 1
if num == 20:
break
i += 1

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值