标签:sheng 一个 for else while end lis 个数 python
game_list=['xiaoziaokan','kaixinxiaole','tiaoyitiao','chaojimali','ranzheshengui','hundluo']
ins=0
while ins < 6:
print(game_list[ins])
ins += 1
xiaoziaokan
kaixinxiaole
tiaoyitiao
chaojimali
ranzheshengui
hundluo
for的运用
for i in 列表or字典:
print(i)i代表了是字典或列表的值
for i in game_list:
print(i)
xiaoziaokan
kaixinxiaole
tiaoyitiao
chaojimali
ranzheshengui
hundluo
for i in game_list:
if i == 'chaojimali':
break #循环到chaojimali这里停止所以输出的是前三个
print(i)
xiaoziaokan
kaixinxiaole
tiaoyitiao
for i in game_list:
if i == 'chaojimali':
continue #循环到chaojimali这里跳过除了chaojimali不输出其他正常输出
print(i)
xiaoziaokan
kaixinxiaole
tiaoyitiao
ranzheshengui
hundluo
for i in game_list:
if i == 'chaojimali':
continue #循环到chaojimali这里跳过除了chaojimali不输出其他正常输出
print(i)
else:
print('我没有被跳过')
xiaoziaokan
kaixinxiaole
tiaoyitiao
ranzheshengui
hundluo
我没有被跳过
for i in game_list:
if i == 'chaojimali':
break #循环到chaojimali这里跳过除了chaojimali不输出其他正常输出
print(i)
else:
print('我被跳过了')
xiaoziaokan
kaixinxiaole
tiaoyitiao
print('laoding',end='')
for i in range(6):
print('.',end='')
laoding......
n = 5
for i in range(1, n+1): # 控制三角形的高,也就是层数
for k in range(2*(n-i)): # 控制每层第一个*的空格,从最后一层往上数分别是0, 2, 4, 6....,因为三角形越大,
#第一层空格反而越多,想起这个应该跟i
#有关,而且肯定是被减的那个数,发现刚好是2n-2i
print("",end=" ")
for j in range(1, 2*i): # 控制每层*的个数,由于是1,3,5,7,9...所以很快知道是2i-1
print("*",end=' ')
print()
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
n = 5
for i in range(1, n+1): # 控制三角形的高,也就是层数
for k in range(2*(n-i)): # 控制空格
print("",end=" ")
if 1 < i < n:
print("*",end="")
for j in range(1, (2*(i-1)-1)*2 + 1 +1):
print(" ",end='')
print("*", end="")
else:
for j in range(1, 2*i): # 控制每层*的个数,由于是1,3,5,7,9...所以很快知道是2i-1
print("*",end=' ')
print()
*
* *
* *
* *
* * * * * * * * *
标签:sheng 一个 for else while end lis 个数 python
原文地址:https://www.cnblogs.com/linjiahua/p/12111261.html