[英]Python: Two Nested Loops
I'm trying to find coding for Python version 3 doing these two things in basic coding (a loop nested inside another loop). 我试图找到在基本编码(嵌套在另一个循环内的循环)中做这两件事的Python版本3的编码。 I understand the basic premise of:
我了解以下基本前提:
for i in range(10)
for j in range(10)
but I think it's the "i+___" math that's giving me trouble. 但我认为正是“ i + ___”数学给我带来了麻烦。 I'm having trouble giving me these three types of outputs:
我无法提供以下三种类型的输出:
First: 第一:
0
0 1
0 1 2
0 1 2 3
Second: 第二:
10
11 12
13 14 15
16 17 18 19
Third: 第三:
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
Any help would be greatly appreciated. 任何帮助将不胜感激。
Third: 第三:
j=[]
for i in xrange(0,3):
j.append([i]*9)
For python version 3. 对于python版本3。
First: 第一:
for i in range(4):
for j in range(i+1):
print(j, end="")
print()
Second: 第二:
x=10
for i in range(1,5):
for j in range(x,i+x):
print(str(j)+" ", end="")
x+=i
print()
Third: 第三:
for i in range(3):
print((str(i)+" ")*9)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.