1.字符串格式化

name="suwukong"

print("欢迎",name,"光临")
print("欢迎 "+name+" 光临")
print("欢迎 %s 光临" %name)
print(f"欢迎 {name} 光临")

python-while循环,for ,以及字符串格式化

2.用while 打印三角形

i = 1
while i<=4:
    j=1
    while j<=i:
        print("*",end="")
        j=j+1
    print("")
    i=i+1

python-while循环,for ,以及字符串格式化

2.九九乘法表

a = 1
while a <= 9:
    b = 1
    while b <= a:
        print("%s * %s = %s\t "%(b,a,a*b),end="")
        b = b + 1
    print("")
    a = a + 1

python-while循环,for ,以及字符串格式化

3.打印矩形

j = 1
while j<=4:
    k=1
    while k<=5:
        print("*",end="")
        k=k+1
    print("")
    j=j+1

python-while循环,for ,以及字符串格式化

 

相关文章:

  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
猜你喜欢
  • 2021-08-15
  • 2022-12-23
  • 2021-07-07
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案