九九乘法表最后 print("\n") 缩进不同结果不一样啊
本帖最后由 少年白马入江湖 于 2021-7-1 17:03 编辑SyntaxError: unindent does not match any outer indentation level
>>> for i in range(1, 10):
for j in range(1, i+1):
print(i, "x", j, "=", i * j, end=' ')
print("\n")
1 x 1 = 1
2 x 1 = 2
2 x 2 = 4
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
8 x 1 = 8
8 x 2 = 16
8 x 3 = 24
8 x 4 = 32
8 x 5 = 40
8 x 6 = 48
8 x 7 = 56
8 x 8 = 64
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81
>>> for i in range(1, 10):
for j in range(1, i+1):
print(i, "x", j, "=", i * j, end=' ')
print("\n")
SyntaxError: unexpected indent
>>> for i in range(1, 10):
for j in range(1, i+1):
print(i, "x", j, "=", i * j, end=' ')
print("\n")
1 x 1 = 1
2 x 1 = 2 2 x 2 = 4
3 x 1 = 3 3 x 2 = 6 3 x 3 = 9
4 x 1 = 4 4 x 2 = 8 4 x 3 = 12 4 x 4 = 16
5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25
6 x 1 = 6 6 x 2 = 12 6 x 3 = 18 6 x 4 = 24 6 x 5 = 30 6 x 6 = 36
7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49
8 x 1 = 8 8 x 2 = 16 8 x 3 = 24 8 x 4 = 32 8 x 5 = 40 8 x 6 = 48 8 x 7 = 56 8 x 8 = 64
9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81
为何你发的求助帖都是收费贴?
别人回答问题还要给你付鱼币?
别人解决你的问题你也不采纳。 hrpzcf 发表于 2021-7-1 16:50
为何你发的求助帖都是收费贴?
别人回答问题还要给你付鱼币?
别人解决你的问题你也不采纳。
是吗?我以为是付费 少年白马入江湖 发表于 2021-7-1 16:57
是吗?我以为是付费
给你们
{:10_312:}其实print中不用加\n的,默认print中就是\n换行,直接print()就行 另外就是按照前一个的写法,是在每次第二层循环中打印一次,而后面一个写法是在第二次循环结束后打印一次,结果肯定不一样 首先要分清楚两层for循环都是干嘛的
内层循环单次打印一个乘法语句
外层循环单次打印一行乘法语句
所以print('\n')放到内层循环内,就是每打印一句换行依次(即第一种情况)
放到内层循环外,外层循环内,就是对应打印完一行再换行(合理情况) 取决于在的层数 那肯定不一样啊
页:
[1]