600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 通过while循环一步步实现九九乘法表

通过while循环一步步实现九九乘法表

时间:2023-09-24 18:55:06

相关推荐

通过while循环一步步实现九九乘法表

# 打印#做出@列的效果

height = int(input("height: ")) #用户输入一个高度

num_height = height

while num_height > 0:

print("@")

num_height -= 1

# 打印#做出@列的效果

width = int(input("width: ")) #用户输入一个宽度

num_width = 1 #第一步 赋值

while num_width <= width: #第二步 num_width == 1

print("#",end="") #第三步 不换行 打印一个#

num_width += 1 #第四步 num_width == 2

print()

# 打印#做出N行X列的效果

height = int(input("height: ")) #用户输入一个高度

width = int(input("width: ")) #用户输入一个宽度

num_height = 1

while num_height <= height:

num_width = 1

while num_width <= width:

print("#",end="")

num_width += 1

print()

num_height += 1

通过前面的铺垫,现在开始尝试打印九九乘法表

#九九乘法表

first = 1

while first <=9:

second = 1

while second <= first:

print(str(second)+"*"+str(first)+"="+str(second*first),end="\t")

second +=1

first +=1

print()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。