i = 0
while i<5:
j = 0
while j<=i:
print("*",end="")
j+=1
print("")
i+=1
等腰三角形
n=9
for i in range(n):
for j in range(i):
print(' ',end='')
for k in range(i,n):
print('* ',end='')
print()
九九乘法表
i=1
while i<=9:
j=1
while j<=i:
print("%s*%s=%s "%(j,i,j*i),end="")
j+=1
print("")
i+=1
for i in range(1,10):
for n in range(1,i+1):
print('%s*%s=%s'%(i,n,i*n),end=' ')
print()
使用for循环输出数字0-9,当数字为6时,跳出本次循环,执行其他循环
当数字为8的时候,停止循环
for i in range(0,10):
if i == 6:
continue
elif i == 8:
break
else:
print(i)
使用循环 计算出1-100之间 所有基数的和,偶数和
a=0
for i in range(0,100):
if i % 2 == 0:
# print(i,end=' ')
a+=i
print("偶数和是:",a)
b=0
for i in range(0,100):
if i % 2 != 0:
# print(i,end=' ')
b+=i
print("奇数和是:",b)