Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么嵌套for循环提前结束?(python)_Python_For Loop_Nested Loops - Fatal编程技术网

为什么嵌套for循环提前结束?(python)

为什么嵌套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

如果我把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 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)
    可能的