0
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))

If I were to put 1(start_inner), 3(end_inner), 1(start_outer), 2(end_outer)

I should get:

1 1
1 2
1 3
2 1
2 2
2 3

Instead i get:

1 1
1 2

Any help is appreciated thanks.

mitch
  • 23
  • 3
  • 1
    The end of a range is not inclusive (exclusive). `range(1, 3)` will yield `(1, 2)` – Moberg Aug 30 '18 at 09:53
  • Possible duplicate of [Why are slice and range upper-bound exclusive?](https://stackoverflow.com/questions/11364533/why-are-slice-and-range-upper-bound-exclusive) – U13-Forward Aug 30 '18 at 09:59

2 Answers2

1

pythons range(1,5) is non-inclusive for the end-term - meaning it will only loop from 1 to 4. Read more regarding this topic here :-)

Cut7er
  • 1,209
  • 9
  • 24
1

@Cut7er is right, but here is he solution:

...
for outer in range(start_outer, end_outer+1):
    for inner in range(start_inner, end_inner+1):
        print("{:^2} {:^2}".format(outer, inner))

My Explanation:

  1. range includes first value

  2. range excludes second value

See: this

U13-Forward
  • 69,221
  • 14
  • 89
  • 114