循环

# 输出九九乘法表
i = 1 while i<=9: j = 1 while j <= i: print("\t%s * %s = %s" %(j, i, i*j), end=" ") j += 1 i += 1 print("")

2. 使用*输出长方形,长宽由用户输入

long = int(input("请输入长度(整数):"))
weight = int(input("请输入宽度(整数):"))

i = 1

while i <= weight:
    j = 1
    while j <= long:
        print("*",end="")
        j += 1
    i += 1
    print("")
long = int(input("请输入长度(整数):"))
weight = int(input("请输入宽度(整数):"))

i = 1

while i <= long:
    print("* " * weight)
    i += 1

 

3.用*打印三角形

  1)打印直角三角形

# 利用字符串运算符
num = int(input("请输入整数:"))

i = 1

while i <= num:
    print("* " * i)
    i += 1
num = int(input("请输入整数:"))

i = 1

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

输出:

  2)倒序三角形,相减即可

  3)直角在这边

# 利用字符串运算符
num = int(input("请输入整数:"))

i = 1

while i <= num:
    str = "*" * i
    print(" " * (num - i), end=str)
    i += 1
    print("")

 

posted on 2018-03-30 10:27  今日的小白白  阅读(185)  评论(0编辑  收藏  举报

导航