1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > python学习之循环语句的九九乘法表

python学习之循环语句的九九乘法表

时间:2020-04-30 12:43:06

相关推荐

python学习之循环语句的九九乘法表

while 语句的九九乘法表:

##九九乘法表

#总共有九行

# 每行中的列数,就是当前所处的行号

#乘式的第一个数代表的是列,第二个数代表的是行

row = 1

#行

column = 1

#列

while row <= 9:

while column <= row:

print('%d * %d = %d, '%(column,row,column * row),end='')

column += 1

print('') #换行

row += 1

column = 1

for 语句的九九乘法表:

for row in range (1,10):

for column in range(1,row +1):

print('%d * %d = %d, '%(column,row,column * row,),end="")

column +=1

print(' ')

row += 1

column = 1

输出结果如下:

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