为什么嵌套for循环提前结束?(python)
如果我把1(内部开始),3(内部结束),1(外部开始),2(外部结束) 我应该得到:为什么嵌套for循环提前结束?(python),python,for-loop,nested-loops,Python,For Loop,Nested Loops,如果我把1(内部开始),3(内部结束),1(外部开始),2(外部结束) 我应该得到: first_name = input("Please enter your first name: ").capitalize() start_inner = int(input("Hi {}, please enter the start value for the inner loop: ".format(first_name))) end_inner = int(input("Please enter
first_name = input("Please enter your first name: ").capitalize()
start_inner = int(input("Hi {}, please enter the start value for the inner
loop: ".format(first_name)))
end_inner = int(input("Please enter the end value for the inner loop: "))
start_outer = int(input("Please enter the start value for the outer loop: "))
end_outer = int(input("Please enter the end value for the outer loop: "))
for outer in range(start_outer, end_outer):
for inner in range(start_inner, end_inner):
print("{:^2} {:^2}".format(outer, inner))
相反,我得到:
1 1
1 2
1 3
2 1
2 2
2 3
感谢您的帮助。pythons
范围(1,5)
对于结束术语是不包含的-这意味着它将仅从1循环到4。阅读有关此主题的更多信息:-)pythons范围(1,5)
对于结束项是不包含的-这意味着它将仅从1循环到4。阅读有关此主题的更多信息:-)@Cut7er是正确的,但以下是他的解决方案:
1 1
1 2
我的解释是:
范围
包括第一个值范围
不包括第二个值请看:@Cut7er是对的,但他的解决方案如下:
1 1
1 2
我的解释是:
范围
包括第一个值范围
不包括第二个值请参阅:范围的末尾不包含(独占)<代码>范围(1,3)将产生
(1,2)
范围末尾的可能重复项不包括(排除)<代码>范围(1,3)将产生(1,2)
可能的