for i in range(50): i =+ 1 print(i)
Here is what the above code is Doing:
1. It’s creating a variable called i and setting it to 0.
2. It’s creating a for loop that will run 50 times.
3. It’s creating a variable called i and setting it to 0.
4. It’s adding 1 to the variable i.
5. It’s printing the variable i.
6. It’s going back to step 3 and repeating the process.
The problem is that the variable i is being created and set to 0 every time the loop runs.
The solution is to create the variable i outside of the loop.