For 1. to clarify the loop as a whole is not irrelevant. What the _ specifically means is this:
When the iterator is set to “_” it means that the iterator is not used within the loop and can be ignored by the developer.
However this does not mean it is ignored by the program, it still functions as a normal loop and the program still requires the loop to be run. This is a purely visual point to demonstrate to future developers that the value of the iterator is not used within the loop, and it is purely for running the same code a set number of times. Therefore if there is a bug in the loop code, it is not related to the value of the iterator.
For 2., the reason the for loop code is skipped is because of how the loop is working. It runs for each number in
range(num // val[i]). When
num = 1, we have
range(1 // val[i])
Now in python, the
// operator does an integer division, which means that you won’t get decimal numbers. This has the knock-on effect meaning that for any division where
num < val[i], the value will be 0, since any number less than 1 will be set to 0 by the
// operator. Therefore when
num = 1, for all values in val[i], we will get
for _ in range(0):
# code here
where range(0, 0) is just null. Therefore there’s nothing to loop through and as such the loop is skipped. For completeness when
val[i] = 1 the code will run, as range(1) is just the number 0, and so the code will run a single time.
Hopefully this explains everything well to you, ask if you have any other questions!