标签:+= play 打印 cli gif color pre spl end
实例1:九九乘法口诀表
for i in range(9,0,-1): for k in range(1,i): print(end = " ") for j in range(i,10): print("{}*{}={}\t".format(j,i,j*i),end = "") print()
实例2:输入奇数打印菱形
a = int(input("请输入行数(必须是奇数):")) for i in range((-a//2),(a//2+1)): print(" "*abs(i)+"*"*(a-2*abs(i))) a = int(input("请输入行数(必须是奇数):")) i = -a//2+1 while i <= a//2: print(" "*abs(i),end="") print("*"*(a-2*abs(i))) i += 1
a = int(input("请输入行数(必须是奇数):")) for i in range((-a//2),(a//2+1)): print(" "*abs(i)+"*"*(a-2*abs(i)))
实例3:星号塔层数
n = int(input("请输入星号塔的层数:")) for i in range(n,0,-1): print("{} {}".format(" "*(i-1),"*"* (2*(n-i)+1)))
参考菜鸟教程:https://www.runoob.com/python/python-for-loop.html
参考W3school:https://www.w3school.com.cn/python/python_for_loops.asp
标签:+= play 打印 cli gif color pre spl end
原文地址:https://www.cnblogs.com/qi1113/p/12349633.html