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

你可能感兴趣的:(Python笔记)