文章目录
1. 打印9*9乘法表
#打印9*9乘法表
for i in range(1,10):
for k in range(1,i+1):
print(f"{k} * {i} = {i*k}",sep="" ,end="\t")
print();
2. 打印菱形
思路一:建立坐标系,根据数学坐标系判断菱形取值范围。打印
#打印菱形,第一总思路,数学公式判断边界
border = int(input("请输入菱形边长:"))
for y in range(border-1,-border,-1):
for x in range(-border,border):
if y < x + border and y> x-border and y<-x+border and y> -x- border:
print("*",sep="",end="")
else:
print(" ",sep="",end="")
print();
思路二:上下对称打印
border = int(input("请输入菱形边长:"))
up = "";
down = "";
for i in range(1,border):
starr = " "*(border-i) +"*"*i +"*"*(i-1)+" "*(i-1)
up += starr +"\n"
down = "\n" + starr + down
end = "*"*(border+border-