2 Respuestas
+ 2
Thx for answer
31st Jan 2024, 6:45 AM
Arfagon _30
Arfagon _30 - avatar
+ 2
Arfagon _30 , Yeah. I think you're confused about scope or namespace. The top-level identifiers i and i1 are different identifiers than the formal parameters i and i1 inside your function. So, for example, in your calling loop, i and i1 keep reusing the same values 1 and 0, which you can see by adding a print statement. for _ in range(len(num)): schet(p,i,i1,num) i=i1+1 print(i, i1) # 1 0 Also, a general red flag for non-pythonic thinking or thinking that comes from using loops in other languages, is when you find yourself using len(iterable) in the header of a loop. Python loops are designed to easily iterate an iterable directly, without needing to specify the length, so there's usually a simpler way. In other words, this, for _ in range(len(num)): can be pythonically reduced to this. for _ in num:
31st Jan 2024, 7:20 PM
Rain
Rain - avatar