Question about Python for door.

Asked 2 years ago, Updated 2 years ago, 70 views

It's a question from Python about For Moon Implemented as follows


n = 10
for i in range(0, n-1):
    // Now we understand that n is 9
    for j in range(i + 1, n):
        // So n here is going to be the 10 declared above 
        // I wonder if it will be 9 which is the n-1 value of the for statement above one level.
        // It's 9 in code, but I don't understand why it's 9
        print("i = ",i,"// j = ",j)

It's a very basic question, but I'm confused about various algorithms with this for doorcrying Please reply.

for

2022-09-22 16:47

1 Answers

The variable n does not change in the code above.

range (0, n - 1) is the same as range (0, 9).

In the second for, n is of course 10.

The range (0, 10) is expressed from 0 to 9.


2022-09-22 16:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.