brianwang93 发表于 2021-2-1 14:43:00

最新python教程第四讲动动手1

本帖最后由 brianwang93 于 2021-2-2 13:20 编辑

如何把小的数放在前面,例如:
1 x 1 = 1
1 x 2 = 2 2 x 2 = 4
1 x 3 = 3

wp231957 发表于 2021-2-1 14:48:24

for x in range(1,10):
   for y in range(1,x+1):
      print(y,"*",x,"=",x*y,end="")
   print()   

D:\wp>py wp\wp1.py
1 * 1 = 1
1 * 2 = 22 * 2 = 4
1 * 3 = 32 * 3 = 63 * 3 = 9
1 * 4 = 42 * 4 = 83 * 4 = 124 * 4 = 16
1 * 5 = 52 * 5 = 103 * 5 = 154 * 5 = 205 * 5 = 25
1 * 6 = 62 * 6 = 123 * 6 = 184 * 6 = 245 * 6 = 306 * 6 = 36
1 * 7 = 72 * 7 = 143 * 7 = 214 * 7 = 285 * 7 = 356 * 7 = 427 * 7 = 49
1 * 8 = 82 * 8 = 163 * 8 = 244 * 8 = 325 * 8 = 406 * 8 = 487 * 8 = 568 * 8 = 64
1 * 9 = 92 * 9 = 183 * 9 = 274 * 9 = 365 * 9 = 456 * 9 = 547 * 9 = 638 * 9 = 729 * 9 = 81

小甲鱼的铁粉 发表于 2021-2-1 14:48:42

for i in range(1,10):
    for j in range(1,i + 1):
      print("%d * %d = %d " %(j, i, i * j), end = "")
    print('\n')

brianwang93 发表于 2021-2-1 14:49:34

小甲鱼的铁粉 发表于 2021-2-1 14:48


谢谢解答

小甲鱼的铁粉 发表于 2021-2-1 14:50:33

brianwang93 发表于 2021-2-1 14:49
谢谢解答

没事没事

wp231957 发表于 2021-2-1 15:04:26

论坛里 如此修改标题 是很不好的一个行为

brianwang93 发表于 2021-2-2 13:18:19

wp231957 发表于 2021-2-1 15:04
论坛里 如此修改标题 是很不好的一个行为

感谢提醒,下次不会了~
页: [1]
查看完整版本: 最新python教程第四讲动动手1