脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python使用while循环花式打印乘法表

Python使用while循环花式打印乘法表

2021-05-23 12:06Mr.o.j Python

今天小编就为大家分享一篇关于Python使用while循环花式打印乘法表,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

花式打印9*9乘法表

?
1
2
3
4
5
6
7
8
9
10
11
12
13
#第一个计数器
i = 1
while i < 10:
  #第二个计数器
  j = 1
  while j <= i:
    print('%d*%d=%d\t' %(j, i, i*j) , end=(''))
    j +=1
  #换行
  print('')
  i +=1
#输出换行
print('')

Python使用while循环花式打印乘法表

?
1
2
3
4
5
6
7
8
9
10
11
12
13
i = 1
while i <= 9:
  k = 8
  j = 1
  while k >= i:
    print('\t\t', end=(''))
    k -= 1
  while j <= i:
    print('%d*%d=%d\t' % (j, i, i * j), end=(''))
    j += 1
  print('')
  i += 1
print('')

Python使用while循环花式打印乘法表

?
1
2
3
4
5
6
7
8
9
10
11
12
13
i = 9
while i > 0:
  j = 1
  k = 8
  while k >= i:
    print('\t\t', end=(''))
    k -= 1
  while j <= i:
    print('%d*%d=%d\t' % (j, i, j * i), end=(''))
    j += 1
  print('')
  i -= 1
print('')

Python使用while循环花式打印乘法表

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对服务器之家的支持。如果你想了解更多相关内容请查看下面相关链接

原文链接:https://blog.csdn.net/weixin_40543283/article/details/86572611

延伸 · 阅读

精彩推荐