'''打印1个星星
循环5个星星
打印5行星星
'''
j=0
while j<5:
i=0
while i<5:
print('*',end='') #end是结束符号,‘’就可以连续打出5个星星,‘\n’就可以打出换行
i+=1#现在一行星星结束了
print()#默认是空的就是\n
j+=1
正方形
三角形
j=1
while j<=5:
i=1
while i<=j:
print('*',end='')
i+=1
print()#这里代表着一行完了,需要换行
j+=1
99乘法表
j=1
while j<=9:
i=1
while i<=j:
print(f'{i}*{j}={i*j}',end='\t')#\t 是空格的意思
i+=1
print()
j+=1
for循环
str1='fwefnwoe'
for i in str1:
print(i)
break continue
str1='fejkrbfeoj'
for i in str1:
if i=='o':
print('不打印o')
break
print(i)
continue
str1='fejkrbfeoj'
for i in str1:
if i=='o'
print('不打印o')
continue#如果用while循环就要i+=1,for是不需要的
print(i)
循环的while…else
else 是循环正常结束的时候要执行的代码
i=1
while i<5:
print('cdsc')
i+=1
else:
print('你在说什么')
退出循环对else的影响
i=1
while i<=3:
if i==3:
print('这便说的不真诚')
break
print('媳妇我错了')
else:
print('媳妇说原谅我了')
#break执行后,else就不会执行了
i=1
while i<=5:
if i==3:
print('只一遍的话可以忍受继续道歉')
i+=1
continue
print('媳妇我错了')
i+=1
else:
print('媳妇说原谅我了')#continue下方代码 else也是可以执行的
for …else
str1='bvkejbvoj'
for i in str1:
print(i)
else:
print('循环正常结束执行的代码')
break continue
str1='bvkejbvoj'
for i in str1:
if i=='o':
print('遇到o不打印')
break
print(i)
else:
print('循环正常结束执行的代码')
#此时else不执行
str1='bvkejbvoj'
for i in str1:
if i=='o':
print('遇到o不打印')
continue
print(i)
else:
print('循环正常结束执行的代码')
#此时else执行