I made a very simple code to check if a given inputted number was even or odd. I enclosed the entire block of code in a while-loop . At the end of the block, the user is given the choice to input either "Y" or "N". N changes the value of variable i for which the while loop depends on, so it can never run
This was achieved using if: . However, even if anything other than N is pressed, i's value is still somehow changed and doesn't run again. Here is the code
i = 0
while i == 0:
number= int(input("Enter your number "))
if number%2==0:
print("Your number is even")
else:
print("Your number is odd")
askagain= str(input("Do you wanna enter again? Y or N? \n"))
if askagain == "N" or "n":
i = 1
else:
i = 0
Even if I input Y , the program never loops back. My only fix was swapping
`if askagain == "N" or "n":
i = 1
else:
i = 0`
with
if askagain == "Y" or "y":
i = 0
else:
i = 1
which somehow mysteriously stopped the issue. What exactly is causing i to iterate itself and change its value from 0, even if "N" was not inputted?
There's only one if clause that can iterate i and change its value in such a way, the while loop command never iterates again.
However, even when the if clause is not executed, somehow, i increments itself and the while loop never executes. What's causing i to increment itself?